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

Reply
 
Thread Tools Display Modes
  #1  
Old 01-30-2006, 05:08 PM
tfw2005 tfw2005 is offline
 
Join Date: Sep 2004
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default preg_replace in functions_newpost.php help

Help with a preg_replace call in includes/functions_newpost.php

I currently have a simple preg_replace function working, not in the board system.

I would like to apply it to all new posts before they are inserted into the DB.

This is the original preg_replace

PHP Code:
<?php

$string 
"http://subdomain1.domain1.com/";
$find "/http:\/\/subdomain1\.domain1\.com\//";
$replace "http://www.domain.com/out.php?out=http://subdomain1.domain1.com/";

print 
preg_replace($find$replace$string);

?>
I would like to apply that logic to any instance of http://subdomain1.domain1.com/ that is present in a users post, then enter it into the DB.

I tried the following to no avail in includes/function_newpost.php

PHP Code:

    
// ### POST NEW POST ###


$string "$post['message']";
$find "/http:\/\/subdomain1\.domain1\.com\//";
$replace "http://www.domain.com/out.php?out=http://subdomain1.domain1.com/";

$post['message'] = preg_replace($find$replace$string);


    
$DB_site->query("
            INSERT INTO " 
TABLE_PREFIX "post 

............................... etc 
Any idea how to get that to apply? I saw an amazon affiliates hack that did it, but couldnt get it to work.

Would also be great if the logic could make it so that the link shown is the original link, while the acutal url= part has the rewritten code. For asthetic purposes, because these links can get rather long.


Thanks for the help.
Reply With Quote
  #2  
Old 01-30-2006, 09:54 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What version of vb is this referring to ?
Reply With Quote
  #3  
Old 01-30-2006, 10:59 PM
tfw2005 tfw2005 is offline
 
Join Date: Sep 2004
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

3.03
Reply With Quote
  #4  
Old 01-31-2006, 02:37 AM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In that case sorry, I no longer have 3.0, so I don't have the code handy anymore.
Reply With Quote
  #5  
Old 01-31-2006, 03:54 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

not sure if i got you absolutelly right, but if i did, than this line should be the only one you need:
PHP Code:
$post['message'] = preg_replace(
    
'#(http:\/\/[a-z0-9]+\.[a-z0-9]+\.[a-z0-9]+\/)#i',
    
'[url=http://www.domain.com/out.php?out=\1]\1[/url]',
    
$post['message']
); 
Reply With Quote
  #6  
Old 01-31-2006, 06:07 PM
tfw2005 tfw2005 is offline
 
Join Date: Sep 2004
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey Xenon,

Thanks for the help. That worked, almost.

If i remove the URL BBCode part of your replace section, it works perfect, with no rewrite for the displayed link.

If I leave it in, then I get a double attempt at URL BBcode.

Right now, I took what you posted, and removed that, so I just get a shortened version of the full link, including the initial http://www.domain.com/out.php?out=

Magic wand situation would be if someone types without any BBCODE

http://subdomain1.domain1.com/(variable, whatever EX home.php or blahblahblah/)

this is generated (Look at link via hover)


http://subdomain1.domain1.com/(variable)



And, in theory, if someone posts it with bbcode (in the case of editing a post), the same thing happens.

I can live with this now though, just people see that there is an outbound tracker attached to these specific links.
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 04:25 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.05236 seconds
  • Memory Usage 2,215KB
  • 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_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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