Automatic Hyperlinks

Type ICRT and it get hyberlinked to the knowledge page. Is that done on purpose?

Yup, it is on purpose. There are a few kinks in the system so it’s going through a test-run at the moment.

There are pots of kinks in the system.

I hate it. It’s a good idea, but I hate anything that edits my posts automatically and inserts linksI didn’t put in there.

I’ve re-installed the auto links to The Knowledge. Please help out by:

  1. Looking for inappropriate linking - I’ve removed “ARC” from the list because it shows up in words like “search”
  2. Suggest terms and acronyms that we should include - for ex. a PM for “a private message”
  3. Report any change in forum speed starting today - do you notice anything different in opening Forum pages?

Cheers,

g.

It messed up the word racetrack (not a common word I guess) too, any way to make only do whole words ? Can you put a space before or after it ?
I think the new style looks better.

[quote=“Big Fluffy Matthew”]It messed up the word racetrack (not a common word I guess) too, any way to make only do whole words ? Can you put a space before or after it ?
I think the new style looks better.[/quote]
Hmmm. That’s one we can probably get rid of, since it’s a defunct name (it’s been renamed TAITRA - the Taiwan External Trade Development Council.)

[quote=“Maoman”]Hmmm. That’s one we can probably get rid of, since it’s a defunct name (it’s been renamed TAITRA - the Taiwan External Trade Development Council.)[/quote]I don’t mean to get rid of them, but somehow make it only replace whole words. ARC is a common term that you probably don’t want to get rid of. Or can you make it case sensitive ?

This is another one. Vitriol.

I agree with BFM that making it case sensitive or only applicable to whole words would be good.

Yeah, discovering that this could not distinguish distinct words from text within another words was an unpleasant surprise.

In case you are interested, here is a snippet of the code that I am using. I tried to find the conditional that picks out the targeted words, hoping that I could insert the spaces around it :frowning:


function loadPatterns()
{
    global $aTfPatterns,$aTfUrls,$aTfTabooTokenParts;
    $handle = fopen(C_CA_TF_REPLACEMENTS_FILE_NAME, "r");
    while (!feof($handle)) 
    {
        $strBuffer = fgets($handle, 4096);
        $iPos = strpos($strBuffer,C_CA_TF_REPLACEMENTS_COMMENT);
        if($iPos !== false)
        {
            $strBuffer = substr($strBuffer,0,$iPos);
        }
        $iPos = strpos($strBuffer,C_CA_TF_REPLACEMENTS_SEPARATOR);
        if($iPos !== false)
        {
            $strPattern = trim(substr($strBuffer,0,$iPos));
            $strUrl = trim(substr($strBuffer,$iPos+1));
            array_push($aTfPatterns, $strPattern);
            array_push($aTfUrls, $strUrl);
        }
    }
    fclose($handle);
    $aTfTabooTokenParts = explode(" ", C_CA_TF_TABOO_TOKEN_PARTS);
}

rather than looking for strings within words, can you set the search to include spaces either side? i.e. " ARC " instead of “ARC”

I use that techinque from time to time when I do ctrl-F activity in MS applications and it works ok.

Just a thought.

Captain.

Ha ha . Tavern Captain.

:s

test:

icrt icrt arc arc icrt arc

Result:
Ah… I thought the code posted would do that. I’m sure I can come up with somethink that replaces all occurences, and only whole words. But anyway to test it without blowing up Forumosa ?

why

Maybe summit like:

[quote]$search=array(
‘/WARC/W’,
‘/WJFRV/W’,
);

$replace=array(
‘httpOrBBcodeForARC’,
‘httpOrBBcodeForJFRV’,
);

$text=preg_replace($search,$replace,$text);[/quote]

I’ve never tried php before, so forgive me if it’s all wrong.
‘/WARC/W’ (capital W) is supposed to be a regular expression for ARC surrounded by 2 non-word chars, most likely a space or punctuation
$text is supposed to be the post to be changed, hopefully you know the real name

[quote]rather than looking for strings within words, can you set the search to include spaces either side? i.e. " ARC " instead of “ARC”
[/quote]
Truant, BFM - I wasn’t clear enough earlier - what you both said here is precisely what I was trying to do, but I didn’t see where to make this kind of change in the code I posted up.

change
$strPattern = trim(substr($strBuffer,0,$iPos));
to
$strPattern = ’ ‘.trim(substr($strBuffer,0,$iPos)).’ ';

:idunno:
That’s a pretty ugly bodge and won’t always work, but it may tape over a few holes temporarily
Do you have any more code ? Maybe the whole mod ?

BFM, you did it! Thank you :notworthy: :notworthy: :notworthy:

Here is the rest of the mod, not including the patterns datafile (where the target words and their destination links are stored) and the changes to the phpBB forum pages. I’ve also blanked out the paths to the data directory with the ellipseses


//constants start
define('C_CA_TF_REPLACEMENTS_FILE_NAME', '...'); //file name of the pattern file
define('C_CA_TF_REPLACEMENTS_COMMENT',   '...'); //comment character in the pattern file
define('C_CA_TF_REPLACEMENTS_SEPARATOR', '...'); //separator between pattern and URL in the pattern file
define('C_CA_TF_URL_PATTERN', 'CA_TF_URL_GOES_HERE'); //for C_CA_TF_START_TAG
define('C_CA_TF_START_TAG', '...');
define('C_CA_TF_END_TAG', ' ...'); //file name of the patten file
define('C_CA_TF_TABOO_TOKEN_PARTS', 'http:// HREF= SRC='); //space-separated. If on of parts found in the token, substitute aborted

define('C_CA_TF_TOTAL_REPLACEMENTS', 20); //total replacements per load (call of viewtopic.php)
define('C_CA_TF_TOTAL_BLOCK_REPLACEMENTS', 20); //total replacements per block (block - one call to insertContextAds() )
define('C_CA_TF_TOTAL_REPLACEMENTS_PER_PATTERN', 1); //replacements per pattern in block


//global variables
$aTfPatterns = array();
$aTfUrls = array();
$aTfTabooTokenParts = array();
$iTfTotalCount = 0;
$iTfTotalBlockCount = 0;

//functions

function loadPatterns()
{
    global $aTfPatterns,$aTfUrls,$aTfTabooTokenParts;
    $handle = fopen(C_CA_TF_REPLACEMENTS_FILE_NAME, "r");
    while (!feof($handle))
    {
        $strBuffer = fgets($handle, 4096);
        $iPos = strpos($strBuffer,C_CA_TF_REPLACEMENTS_COMMENT);
        if($iPos !== false)
        {
            $strBuffer = substr($strBuffer,0,$iPos);
        }
        $iPos = strpos($strBuffer,C_CA_TF_REPLACEMENTS_SEPARATOR);
        if($iPos !== false)
        {
            $strPattern = " ".trim(substr($strBuffer,0,$iPos))." ";
            $strUrl = trim(substr($strBuffer,$iPos+1));
            array_push($aTfPatterns, $strPattern);
            array_push($aTfUrls, $strUrl);
        }
    }
    fclose($handle);
    $aTfTabooTokenParts = explode(" ", C_CA_TF_TABOO_TOKEN_PARTS);
}

function insertContextAds( $szBuffer )
{
    global $aTfPatterns,$aTfUrls,$iTfTotalCount,$aTfTabooTokenParts;
    $iTfTotalBlockCount = 0;

    for($i = 0; $i < count($aTfPatterns); $i++)
    {
        if(($iTfTotalBlockCount >= C_CA_TF_TOTAL_BLOCK_REPLACEMENTS) || ($iTfTotalCount >= C_CA_TF_TOTAL_REPLACEMENTS))
        {
            break;
        }

        $iStartPos = 0;
        $iEndPos = 0;
        for($j = 0; $j < C_CA_TF_TOTAL_REPLACEMENTS_PER_PATTERN; $j++)
        {
            //$iStartPos = stripos( $szBuffer, $aTfPatterns[$i], $iStartPos ); //use in php 5 +
            $iStartPos = strpos( strtoupper($szBuffer), strtoupper($aTfPatterns[$i]), $iStartPos ); //comment in php 5 +
            if($iStartPos !== false)
            {
                $iOldEndPos = $iEndPos;
                $iEndPos = $iStartPos + strlen($aTfPatterns[$i]) ;


                $bNoTabooParts = true;
                $strTmp = substr($szBuffer,$iOldEndPos,$iStartPos);
                $strTmp = strrev($strTmp);


                $iStartTokenPos = $iStartPos - strcspn ($strTmp, " ><\n\t",0);
                $iEndTokenPos = $iEndPos + strcspn ($szBuffer, " ><\n\t",$iEndPos);
                $strToken = substr($szBuffer,$iStartTokenPos, $iEndTokenPos - $iStartTokenPos );

                for($t = 0; $t < count($aTfTabooTokenParts); $t++)
                {
                    if(strpos($strToken,$aTfTabooTokenParts[$t]) !== false)
                    {
                        $bNoTabooParts = false;
                        break;
                    }
                }

                if($bNoTabooParts === true)
                {
                    $strToReplace = substr($szBuffer,$iStartPos, strlen($aTfPatterns[$i]) );
                    $strReplacement = str_replace( C_CA_TF_URL_PATTERN, $aTfUrls[$i], C_CA_TF_START_TAG) . $strToReplace . C_CA_TF_END_TAG;
                    $szBuffer = substr($szBuffer,0,$iStartPos) . $strReplacement .  substr($szBuffer,$iEndPos);
                    $iStartPos = $iStartPos + strlen($strReplacement);
                    $iTfTotalBlockCount++;
                    $iTfTotalCount++;
                    if(($iTfTotalBlockCount >= C_CA_TF_TOTAL_BLOCK_REPLACEMENTS) || ($iTfTotalCount >= C_CA_TF_TOTAL_REPLACEMENTS))
                    {
                        break;
                    }
                }
                else
                {
                    $iStartPos = $iEndPos;
                }
            }
        }
    }
    return $szBuffer;
}

loadPatterns();
?>

$strPattern = ’ '.trim(substr($strBuffer,0,$iPos));
Might took a tad better and not put a space between the word and the little icon thingy

[quote=“Big Fluffy Matthew”]$strPattern = ’ '.trim(substr($strBuffer,0,$iPos));
Might took a tad better and not put a space between the word and the little icon thingy[/quote]
I hadn’t noticed the space between the link and the little icon thingy. But I’ve made the change. If there are many annoying references to the arctic on this forum, we can easily change it back :slight_smile: