Hot Linking

Discussions about the phpBB2 Forum. How to get the best from this powerful script.

Moderator: Moderators

Hot Linking

Postby daddyo » Fri Sep 14, 2007 8:39 pm

Is there a Mod for Hot Linking -- making certain links linkable inside a post body?

Suppose someone is talking about Amazon, for example. I would want to have my system hot link Amazon so it appears as this:

Amazon

I tried doing this with the Word Censor, but if I create an entry with that such as

amazon -> amazon.com

Then, when someone posts "amazon.com", the word censor kicks in, replacing the "amazon", and I end up with

amazon.com.com
daddyo
 
Posts: 47
Joined: Wed Sep 12, 2007 6:05 pm

Advertisement

Postby dcz » Sun Sep 16, 2007 12:18 pm

It should work with the censor system.

Try :

amazon -> <a href="http://www.amazon.com">amazon</a>

But this will cause some problem when trying to edit the entry, you'll have to do it with phpmyadmin to make it simple.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21238
Joined: Fri Apr 28, 2006 9:03 pm

Postby daddyo » Sun Sep 16, 2007 4:19 pm

I don't have HTML enabled, so mine will have to be with BBCODE.

Amazon -> [url =http://www.amazon.com]amazon[/url]

Is there any way to have it search for lowercase/uppercase and replace, instead of making an entry for every possible version of "AmAzOn"???
daddyo
 
Posts: 47
Joined: Wed Sep 12, 2007 6:05 pm

Postby SeO » Sun Sep 16, 2007 4:20 pm

html is not activated here either.
SeO
Admin
Admin
 
Posts: 6333
Joined: Wed Mar 15, 2006 9:41 pm

Postby daddyo » Sun Sep 16, 2007 5:21 pm

Interesting. I never knew you could replace a word with HTML and have it display when HTML was turned off.

OK, so back to my question...

Can I have it search for all versions of a word (upper and lower) and wrap them with HTML tagging?

That'd be an edit in the code, right?

** I have discovered an issue **

Doing this replacement:

amazon -> <a href="http://www.amazon.com">amazon</a>


Replaces the word in my thread titles in viewforum.php and renders the link into the thread unclickable. Instead, it links the word "Amazon" to www.amazon.com and makes the rest of the title unlinked, so the only way to click into the thread is by clicking the "Last Post" graphic at the end of the line (which is very unclear to users).
daddyo
 
Posts: 47
Joined: Wed Sep 12, 2007 6:05 pm

Postby dcz » Tue Sep 18, 2007 10:58 am

Well yes, the censoring system is not really meant to do this.

You could hard code some custom replacement arrays, the code dealing with censoring in viewtopic.php is the following:

Code: Select all
   if (count($orig_word))
   {
      $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);

      if ($user_sig != '')
      {
         $user_sig = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $user_sig . '<'), 1, -1));
      }

      $message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $message . '<'), 1, -1));
   }


So you could add something like :

Code: Select all
   if (count($link_word))
   {
      $message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$link_word, \$replacement_link, '\\0')", '>' . $message . '<'), 1, -1));
   }


Where $link_word would be the array of the word to be replaced by links, and $replacement_link the array of the corresponding links.

This way, you would only be filtering the message body, and not the titles on anything else unattended.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21238
Joined: Fri Apr 28, 2006 9:03 pm

Postby daddyo » Tue Sep 18, 2007 12:53 pm

Thanks...

Unfortunately, I can't seem to get it to work...

I posted a message with 4 different versions of the word amazon...

AMazOn

amazon

amazon.com

www.amazon.com


And put the following code in:

$link_word=array("amazon");
$replacement_link=array("www.amazon.com");
if (count($link_word))
{
$message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$link_word, \$replacement_link, '\\0')", '>' . $message . '<'), 1, -1));
}


But it doesn't seem to do anything.

I tried putting the code segment in different places but it still seems to glance over it and ignore it.
daddyo
 
Posts: 47
Joined: Wed Sep 12, 2007 6:05 pm

Postby dcz » Thu Sep 20, 2007 8:02 am

All right, the full story is you need to prepare the word list a bit.

So the handiest would be to add the list in at the beginning of viewtopic.php if you only want to parse custom replacement in topics.

So try adding :
Code: Select all
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
$link_word=array('amazon', 'myotherword');
$replacement_link=array('<a href="http://www.amazon.com">amazon</a>', '<a href="http://www.example.com">myotherword</a>');
foreach ($link_word as $key => $value) {
   $link_word[$key] = '#\b(' . str_replace('\*', '\w*?', preg_quote($value, '#')) . ')\b#i';
}
// www.phpBB-SEO.com SEO TOOLKIT END


Before :
Code: Select all
//
// Okay, let's do the loop, yeah come on baby let's do the loop
// and it goes like this ...
//
for($i = 0; $i < $total_posts; $i++)


You of course can add other words there, and their replacement, but you need to use full html links for them to work.

And then :

Code: Select all
   // www.phpBB-SEO.com SEO TOOLKIT BEGIN
   if (count($link_word)) {
      $message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$link_word, \$replacement_link, '\\0')", '>' . $message . '<'), 1, -1));
   }
   // www.phpBB-SEO.com SEO TOOLKIT END


after :
Code: Select all
   if (count($orig_word))
   {
      $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);

      if ($user_sig != '')
      {
         $user_sig = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $user_sig . '<'), 1, -1));
      }

      $message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $message . '<'), 1, -1));
   }


It is not case sensitive, so AmaZon will be replaced the same as amazon in this example.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21238
Joined: Fri Apr 28, 2006 9:03 pm

Postby daddyo » Fri Sep 21, 2007 3:53 pm

Awesome!

I wish I knew the phpBB code a bit more to be able to do this myself. :(

The only issue so far I could find with this hack, though, is that

if someone posts -www.amazon.com, the www.amazon part gets a link to www.amazon.com, but the remaining .com doesn't, so the link looks weird (like below)

www.amazon.com

This is what the HTML source looks like:

<a href="http://www.mysite.com/redirect.php?url=http://www." target="_blank">www.</a><a href="http://www.amazon.com">amazon</a>.com

I guess I need to add some kind of ignore functionality, since the regular linking will likely link it if it's in the form of -www.SOMEWEBSITE.com, right?
daddyo
 
Posts: 47
Joined: Wed Sep 12, 2007 6:05 pm

Postby dcz » Mon Sep 24, 2007 10:23 am

You can try to put this code before :

Code: Select all
   $message = make_clickable($message);


in viewtopic.php, just in case it's enough ;)

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21238
Joined: Fri Apr 28, 2006 9:03 pm


Return to phpBB2 Forum

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 44 guests