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

Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2010, 06:05 PM
DamasGate DamasGate is offline
 
Join Date: Aug 2003
Posts: 75
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to exclude url tage

Hello,

I use plugin.

But i need to exclude url's "Anchor Text" inside post's to NOT effected.

Any help please?

Thank you
Reply With Quote
  #2  
Old 10-10-2010, 06:15 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What hook is your replacement plugin using, is it before or after bbcode replacement?
Reply With Quote
  #3  
Old 10-10-2010, 06:20 PM
DamasGate DamasGate is offline
 
Join Date: Aug 2003
Posts: 75
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

postbit_display_complete

Thanks for help
Reply With Quote
  #4  
Old 10-10-2010, 07:21 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, there may be some more elegant way someone knows to do it (in which case, please post it), but here's what I came up with:

Code:
$word = array(
'google',
'yahoo'
);

$link = array(
'<a href="http://google.com">google</a>',
'<a href="http://yahoo.com">yahoo</a>'
);

$parts = preg_split('#(<a|</a)#i', $this->post['message'], -1, PREG_SPLIT_DELIM_CAPTURE);

$newmsg = '';
$inlink = false;
foreach ($parts as $part)
{
    if (strcasecmp($part, "<a") == 0)
        $inlink = true;
    else if (strcasecmp($part, "</a") == 0)
        $inlink = false;
    else if (!$inlink)
        $part = str_replace($word, $link, $part);
    $newmsg .= $part;
}

$this->post['message'] = $newmsg;
I haven't tested it extensively so if you try it you might want to check a lot of posts to make sure they look OK.
Reply With Quote
  #5  
Old 10-10-2010, 09:44 PM
DamasGate DamasGate is offline
 
Join Date: Aug 2003
Posts: 75
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You are wonderful kh99,

Its work like a CHARM Without any error, YOU ARE GREAT believe me.
If you have a website just pm me the link with title, i will add link on my home page PR4 for your website.

Grateful for you and
Thanks a lot



Quote:
Originally Posted by kh99 View Post
OK, there may be some more elegant way someone knows to do it (in which case, please post it), but here's what I came up with:

[code]I haven't tested it extensively so if you try it you might want to check a lot of posts to make sure they look OK.

I am sorry,

There is problem on images TAG
I need to exclude images IMG tags inside post's to NOT effected.

I am sorry kh99, please help me to fix it.


Thank you
Reply With Quote
  #6  
Old 10-11-2010, 07:42 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, I had a feeling you'd evenutally find a problem with that. It's hard to get stuff like that to be bulletproof (or at least it's hard for me).

Anyway, try this:

Code:
$word = array(
'google',
'yahoo'
);

$link = array(
'<a href="http://google.com">google</a>',
'<a href="http://yahoo.com">yahoo</a>'
);

// Match any HTML tag, this will be the delimiter in preg_split
$regexp = "/(<\/?\w+((\s+(\w|\w[\w-]*\w)(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>)/i";

// Capture delimiters and offsets. This will also capture things multiple times because of the
// multiple parens used in the pattern, so we'll have to skip them in the loop below
$parts = preg_split($regexp, $this->post['message'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE);

$newmsg = ''; 
$intag = false;
$offset = 0;
foreach ($parts as $part) // $part is array, 0 = string 1 = offset (because of PREG_SPLIT_OFFSET_CAPTURE)
{
    if ($part[1] < $offset) // ignore parts from other parens in regexp
        continue;
    $offset = $part[1] + strlen($part[0]);

    if (strncasecmp($part[0], '<a', 2) == 0 || 
        strncasecmp($part[0], '<img', 4) == 0)
    {
        if (strcasecmp(substr($part[0], -2), '/>') == 0) // check for self-closed tag
            $intag = false;
        else
            $intag = true;
    }
    else if (strncasecmp($part[0], '</a', 3) == 0 ||
             strncasecmp($part[0], '</img', 5) == 0)
        $intag = false;
    else if (!$intag)
        $part[0] = str_replace($word, $link, $part[0]);
    $newmsg .= $part[0];
}

$this->post['message'] = $newmsg;

It's getting ugly now...
Reply With Quote
  #7  
Old 10-11-2010, 08:27 PM
DamasGate DamasGate is offline
 
Join Date: Aug 2003
Posts: 75
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thats IT,

Great, I really very appreciate your patience and help,


Thank you so much kh99.
Reply With Quote
  #8  
Old 10-11-2010, 10:47 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 would have searched for " google" or "google " (note the space) and replaced them with " <a href="http://google.com">google</a> " and the same for yahoo. Requiring the space as part of the string would mean www.google.com or http://google.com wouldn't be effected. The extra space introduced by the replacement is usually ignored anyway.
Reply With Quote
  #9  
Old 10-11-2010, 11:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's a good idea, that might have solved the OP's problem. I guess since it says "Anchor Text" in the first post I was thinking the problem was the text and not the url. But it might have been a translation thing because it makes more sense that the url would be the problem.
Reply With Quote
  #10  
Old 10-11-2010, 11:48 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

He seems to have edited the first post, I thought this was more in line with what he originally said but now I'm not so sure.
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 05:42 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.07673 seconds
  • Memory Usage 2,251KB
  • 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
  • (2)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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