vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   How to exclude url tage (https://vborg.vbsupport.ru/showthread.php?t=251920)

DamasGate 10-10-2010 05:05 PM

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

kh99 10-10-2010 05:15 PM

What hook is your replacement plugin using, is it before or after bbcode replacement?

DamasGate 10-10-2010 05:20 PM

postbit_display_complete

Thanks for help

kh99 10-10-2010 06:21 PM

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.

DamasGate 10-10-2010 08:44 PM

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 (Post 2108839)
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

kh99 10-11-2010 06:42 PM

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...

DamasGate 10-11-2010 07:27 PM

Thats IT, :D:D:D:D

Great, I really very appreciate your patience and help,


Thank you so much kh99.

BirdOPrey5 10-11-2010 09:47 PM

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.

kh99 10-11-2010 10:09 PM

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.

BirdOPrey5 10-11-2010 10:48 PM

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.


All times are GMT. The time now is 01:45 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.02540 seconds
  • Memory Usage 1,736KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete