Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 06-29-2011, 04:12 PM
The Dawg The Dawg is offline
 
Join Date: Oct 2008
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help with cleaner.php (REGEX)

I need to replace an outdated mods text in posts.

Old code example:
Code:
[ame="http://www.youtube.com/watch?v=wYJ20INbM7Q"]YouTube - ‪Bill O'Reilly Interviews Rapper Lupe Fiasco - 06/20/11‬‏[/ame]
How I want the new code to look:

Code:
[video=youtube;wYJ20INbM7Q]http://www.youtube.com/watch?v=wYJ20INbM7Q[/video]
Regex I was given by a coder:

Code:
$text = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', '[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]', $text);
I do not know where to put this in cleaner.php

I put it here:

PHP Code:
// BACK UP YOUR DATABASE
$replacer = array(
$text preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i',
'[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]'$text
);

// BACK UP YOUR DATABASE 
and it does nothing.

Please tell me how to execute this code.

Thanks
Reply With Quote
  #2  
Old 06-29-2011, 06:06 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What is cleaner.php? Where did you get it from?
Reply With Quote
  #3  
Old 06-29-2011, 06:14 PM
The Dawg The Dawg is offline
 
Join Date: Oct 2008
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by BirdOPrey5 View Post
What is cleaner.php? Where did you get it from?
Cleaner.php is the impex/tools/ folder for Vbulletin.
Reply With Quote
  #4  
Old 06-29-2011, 06:26 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by The Dawg View Post
I need to replace an outdated mods text in posts.

Old code example:
Code:
[ame="http://www.youtube.com/watch?v=wYJ20INbM7Q"]YouTube - ‪Bill O'Reilly Interviews Rapper Lupe Fiasco - 06/20/11‬‏[/ame]
How I want the new code to look:

Code:
[video=youtube;wYJ20INbM7Q]http://www.youtube.com/watch?v=wYJ20INbM7Q[/video]
Regex I was given by a coder:

Code:
$text = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', '[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]', $text);
I do not know where to put this in cleaner.php

I put it here:

PHP Code:
// BACK UP YOUR DATABASE
$replacer = array(
$text preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i',
'[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]'$text
);

// BACK UP YOUR DATABASE 
and it does nothing.

Please tell me how to execute this code.

Thanks

You find this in cleaner.php

PHP Code:
        #$text = preg_replace('##siU', '', $text); 
Change it to this:
PHP Code:
        $text preg_replace('#[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|#siU''[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]'$text); 

Try that. Make sure you have a backup though, I couldn't test this.
Reply With Quote
  #5  
Old 06-29-2011, 07:17 PM
The Dawg The Dawg is offline
 
Join Date: Oct 2008
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Got some progress. :up:

(I am running this on a test database to get the syntax right)

Cleaner ran but I got the error:

Warning: preg_replace(): Compilation failed: unmatched parentheses at offset 48

I looked at the test thread and it deleted the string I want to replace but it did not replace it ( due to the error )

So if I can get the code correct it should work.

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

Success!

Here is the regex pattern that worked:

Code:
$text = preg_replace('|\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)|i', '[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]', $text);
Reply With Quote
  #6  
Old 06-29-2011, 07:44 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I took another look at the code, I think there were a couple typos-

try this line:

Code:
    $text = preg_replace('#\[ame="http://www.youtube.com/watch\?v=([a-z0-9]+)"\](.+)#siU', '[video=youtube;$1]http://www.youtube.com/watch?v=$1[/video]', $text);
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 12:19 PM.


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.04758 seconds
  • Memory Usage 2,223KB
  • 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
  • (8)bbcode_code
  • (4)bbcode_php
  • (2)bbcode_quote
  • (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_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