Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 10-28-2004, 10:11 AM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help me finish my next hack

Hey guys, I haven't been online much since the recent move I did. Don't have much computer access where I'm staying at the moment, but I can't live without my computer and got really bored so I started to dig threw old request threads and saw someone requested a hack to turn a specified 'text' in a post and replace it with a 'url/link'. Well I looked around and didn't find it so I was rather happy that I could make a new hack cause I really didn't know what to do on the computer with no internet, was getting bored. ^^

Anyways, I started to think how I can do this, and it seemed pretty simple actually, just make a new table in the database named 'textlink' with a few needed fields such as 'textlinkid', 'text', and 'link' to hold the info. So I completely finish the admincp part of the hack.

Now the next part was to make it read all the text in each post and check to see if any of the text posted needed to be replaced with a link. This again seemed rather simple to me. I figure I could use the str_replace() function built into PHP. This is where I got a dead end.

Inside that function I need to it read the database field 'text' and replace it with the the info in the database field 'link'. Here's what I think it will look like if I'm not mistaking.

PHP Code:
$post['message'] = str_replace$textvarlinkvar$post['message'] ); 
I believe I need to execute a query to define what to look for, and to define the variables that will be inside the str_replace() function. When I made a query it wouldn't read the info and replace it. Can anyone help me finish this hack? Of course credit definitely goes to everyone who helps. Thanks guys.

Database information:
-Textlink (table name)
---textlinkid (field name for the id of the text/link)
---text (field name for the text to replace)
---link (field name for the url to replace the text with)

Thanks in advance everyone!
Reply With Quote
  #2  
Old 10-28-2004, 06:38 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

do you just replace for newposts or are you changing the bbcode parsing functions?

depending on your answer you'd have to use caching or not of course

as for the general:

PHP Code:
$textlinks $DB_site->query("SELECT * FROM Textlink");
$find = array();
$replace = array();
while (
$link $DB_site->fetch_array($textlinks))
{
$find[] = $link['text'];
$replace[] = '[url=' $link['link'] . ']' $link['text'] . '[/url]';
}
$post['message'] = str_replace($find$replace$post['message']); 
as said, that's the general idea, actually using preg_replace would be better but mor complicated, as it would also allow you to ignore cases and you have to make sure not to replace text which is already a code or url or something like
Reply With Quote
  #3  
Old 10-28-2004, 09:51 PM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey Xenon, again thanks again! I was planing on using the preg_replace() function, but like you said. Its damm complacated. I'm reading about it now in my PHP book. ^^.
Reply With Quote
  #4  
Old 10-29-2004, 04:11 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're welcome

and yeah, play around with the preg_replace. i avoided it in the past as well, as it's very complicated but once you found out the little tricks it's a very strong tool
Reply With Quote
  #5  
Old 10-29-2004, 06:36 PM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure the best place to add this code. I was thinking about doing it in the includes/functions_bbcodeparse.php file and do the query and this:

PHP Code:
$bbcode str_replace($find$replace$bbcode); 
Which works just fine acually, but like you said str_replace() won't take care of the caps and all. So i'm still reading and trying to figure out the preg_replace() function.
Reply With Quote
  #6  
Old 10-30-2004, 12:27 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

putting it into the parse_bbcode function makes it required to cache your $find/$replace arrays, as if you don't do it, you would produce an extra query per post on every page which would be a big no no ^^
Reply With Quote
  #7  
Old 10-30-2004, 11:31 PM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Xenon
putting it into the parse_bbcode function makes it required to cache your $find/$replace arrays, as if you don't do it, you would produce an extra query per post on every page which would be a big no no ^^
Damm i wish i would have read your post before, cause thats what i did and i did notice that every post adds a query but can't figure it out. Maybe you can help me, i posted it as a beta hack and posted all known bugs that i have found. https://vborg.vbsupport.ru/showthread.php?t=71191

Thank man!
Reply With Quote
  #8  
Old 10-31-2004, 11:43 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The answer is already posted there, and it should work the way he posted afaics
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 11:35 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.04156 seconds
  • Memory Usage 2,232KB
  • 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)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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