NP_AutoLink v0.1

Post your new plugins here!
kg
Posts: 541
Joined: Wed Jun 01, 2005 9:59 pm
Location: Germany
Contact:

NP_AutoLink v0.1

Postby kg » Mon Nov 21, 2005 7:52 pm

I have build a new plugin called NP_AutoLink. First I have improved the matching of internet and mail addresses in the NP_Smiley plugin. They are not very sophisticated and they are damage <br> tags, when you have enabled "Convert line breaks" in your blog settings. With the improved regular expressions this doesn't happen.

After that I had the idea, that it would be better to seperate this function from the NP_Smiley plugin to prevent further trouble. So I have build a new plugin for the automatic linking of internet and mail adresses. My suggestion is to remove this function from the NP_Smiley plugin. But that is not my decision.

Here ist code of the NP_AutoLink Plugin:

Code: Select all

<?
/*
  0.1 - initial release
*/

class NP_AutoLink extends NucleusPlugin {

   function getName() { return 'AutoLink'; }
   function getAuthor()  { return 'Kai Greve'; }
   function getURL()  { return 'http://kgblog.de/'; }
   function getVersion() { return '0.1'; }
   function getDescription() {
     return 'Automatically creates links for internet and mail addresses';
   }

   function install() {
     $this->createOption('InternetAddress','Automatically create links for internet addresses ?','yesno','yes');
     $this->createOption('MailAddress','Automatically create links for mail addresses ?','yesno','yes');
   }

   function getEventList() {
     return array('PreItem', 'PreComment');
   }

   function Treatment($_text) {
     global $CONF, $blog;

     if ($this->getOption('InternetAddress') == 'yes') {
         $_text = preg_replace('/(\s)([http|https|ftp|file]+:\/\/[a-zA-Z0-9_?=&%;+-.\/]*)/si','\1<a href="\2">\2</a>',$_text);
         $_text = preg_replace('/(\s)(www\.[a-zA-Z0-9_?=&%;+-.\/]*)/si','\1<a href="http://\2">\2</a>',$_text);
     }

     if ($this->getOption('MailAddress') == 'yes') {
         $_text = preg_replace('/(\s)([a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,5})/s','\1<a href="mailto:\2">\2</a>',$_text);
     }

     return $_text;
   }

   function event_PreItem($_data) {
     $_data[item]->body = $this->Treatment($_data[item]->body);
     $_data[item]->more = $this->Treatment($_data[item]->more);
   }

   function event_PreComment($_data) {
     $_data['comment']['body'] = $this->Treatment($_data['comment']['body']);
   }
}
?>


Could I publish NP_AutoLink to the wiki? What do you think about my suggestion for the NP_Smiley plugin?
User avatar
admun
Nucleus Guru
Nucleus Guru
Posts: 4088
Joined: Mon Oct 20, 2003 2:57 am
Location: San Francisco, CA, USA
Contact:

Re: NP_AutoLink v0.1

Postby admun » Mon Nov 21, 2005 8:26 pm

kg wrote:I have build a new plugin called NP_AutoLink. First I have improved the matching of internet and mail addresses in the NP_Smiley plugin. They are not very sophisticated and they are damage <br> tags, when you have enabled "Convert line breaks" in your blog settings. With the improved regular expressions this doesn't happen.

After that I had the idea, that it would be better to seperate this function from the NP_Smiley plugin to prevent further trouble. So I have build a new plugin for the automatic linking of internet and mail adresses. My suggestion is to remove this function from the NP_Smiley plugin. But that is not my decision.

Here ist code of the NP_AutoLink Plugin:

[stripped]

Could I publish NP_AutoLink to the wiki?

Go ahead. 8)

What do you think about my suggestion for the NP_Smiley plugin?

I guess we can remove the auto link function from NP_Smiley (myself never use it, anyway...), I will keep it as disable by default for now.
kg
Posts: 541
Joined: Wed Jun 01, 2005 9:59 pm
Location: Germany
Contact:

NP_AutoLink published

Postby kg » Mon Nov 21, 2005 9:52 pm

Thank you for your quick responce. :)

I have published the plugin to the wiki: NP_AutoLink.

I think it's a good way to put the auto link feature in a seperate plugin and I'm glad that you agree with this. :)
loopion
Posts: 4
Joined: Tue Nov 22, 2005 3:41 pm
Location: France, Noisy-le-roi

Becareful to spam

Postby loopion » Tue Nov 22, 2005 4:03 pm

Spam robot could browse mails with this system.
Is it possible to add a another option to say "yes" or "no" if we want the mail link with this pattern xxxxxx@xxxx.xxx or xxxxxxA.T.xxxD.O.T.xxx ?

Thanks.
(.oO Loopion Oo.)
kg
Posts: 541
Joined: Wed Jun 01, 2005 9:59 pm
Location: Germany
Contact:

NP_AutoLink v0.2

Postby kg » Wed Nov 23, 2005 12:00 am

That's a very god idea. I have build a new version of the AutoLink plugin that can rewrite mail adresses with [at] and [dot].

You can find it in the wiki: NP_AutoLink.

You can also choose the options that the Plugin don't create links for mail adresses but rewrite the mail adress with [at] and [dot]. This should be the securest way to hide your mail addresses and disapoint spam robots. :)
User avatar
Leng
Nucleus Guru
Nucleus Guru
Posts: 2827
Joined: Sun Sep 19, 2004 2:34 am
Location: Australia
Contact:

Postby Leng » Wed Nov 23, 2005 11:11 am

Can I suggest an option for the user to be able to choose what is substituted for "@" and "." in email addresses?

It seems to me at some future point spambots may become smart enough to recognise address[at]email[dot]com is a valid email address trying to hide from them...
Image
deborahlau.com | To-Do List
Questions? See the FAQ, read the docs, or browse our plugins!!
kg
Posts: 541
Joined: Wed Jun 01, 2005 9:59 pm
Location: Germany
Contact:

NP_AutoLink v0.3

Postby kg » Wed Nov 23, 2005 8:10 pm

I have used your encouragement to build the next release of the NP_AutoLink. Now the user can define the placeholder for @ and . by himself. For example in his own language or something funny. :)

You can find NP_AutoLink v0.3 in the wiki.

I have read that there a serveral ways to hide mail addresses. Maybe I find a solution in Javascript. This could be the securest way.
verbaljam
Posts: 666
Joined: Wed Jul 31, 2002 4:58 pm
Location: Amsterdam, The Netherlands
Contact:

Postby verbaljam » Fri Nov 25, 2005 2:29 pm

Does it have a function to automatically set a target="_blank"? Would come in handy... ;-)
kg
Posts: 541
Joined: Wed Jun 01, 2005 9:59 pm
Location: Germany
Contact:

The problem ...

Postby kg » Fri Nov 25, 2005 11:20 pm

The problem with target="_blank" is that it is no valid XHTML Strict Code. If you wan't to go this way, it's better to build a private fork. I can post the code if you need it. :)

The other way to open a new Window automatically is to use Javascript. This is more tricky but it doesn't damage validity.

But the most important question is the reason why you wan't to do this. I prefer pages without this solution, because every visitor can decide by himself whether he wan't a new browser window or not.

Conclusion: I'm not sure what to do. :?
User avatar
Leng
Nucleus Guru
Nucleus Guru
Posts: 2827
Joined: Sun Sep 19, 2004 2:34 am
Location: Australia
Contact:

Postby Leng » Sat Nov 26, 2005 12:33 am

Image

deborahlau.com | To-Do List
Questions? See the FAQ, read the docs, or browse our plugins!!
kg
Posts: 541
Joined: Wed Jun 01, 2005 9:59 pm
Location: Germany
Contact:

NP_AutoLink v0.4

Postby kg » Sat Nov 26, 2005 2:25 am

I have builded the next Version of NP_AutoLink: the user can decide about open links in a new window. I find a solution with a short Javascript code. Because it's not the normal wish (i hope it :wink: ), I have set the default of the option to No.

As before you can find the new version of NP_AutoLink in the wiki.

@Leng: Your code is a good suggestion too. But if the user hadn't replaced the & with &amp; the correction must be made in the regular expression. Maybe there is a way to test if there's already a replacement. In many cases the & is the reason for invalid XHTML.

It's crazy how many thoughts a little plugin can cause. :)
loopion
Posts: 4
Joined: Tue Nov 22, 2005 3:41 pm
Location: France, Noisy-le-roi

I think it's complete !

Postby loopion » Mon Nov 28, 2005 12:11 pm

I think it's totally complete. No ?

Maybe could it be useful (not personnaly) to convert ftp:// or https:// and others protocol in links ? Maybe the last modification.
(.oO Loopion Oo.)
kg
Posts: 541
Joined: Wed Jun 01, 2005 9:59 pm
Location: Germany
Contact:

Feature already included

Postby kg » Mon Nov 28, 2005 11:01 pm

This is already included in version 0.4:

Code: Select all

$_text = preg_replace('/(\s)([http|https|ftp|file]+:\/\/[a-zA-Z0-9_?=&%;+-.\/]*)/si','\1<a href="\2" '.$nw.'>\2</a>',$_text);


Nevertheless thanks for your hint. :)
User avatar
yama
Posts: 122
Joined: Tue Dec 05, 2006 2:23 pm
Contact:

Postby yama » Wed Sep 26, 2007 7:12 am

http://japan.nucleuscms.org/bb/viewtopi ... 0360#20360

NP_AutoLink I just modified it for multilingual support.
mikmak
Posts: 1
Joined: Mon Aug 11, 2014 7:57 pm
Location: Ireland

NP_AutoLink in latest php

Postby mikmak » Mon Aug 11, 2014 8:02 pm

I know its 2014, but I still use Nucleus and I just upgraded to v3.66 and AutoLink doesn't work - it needs the first line to be changed to
<?php
to work with PHP v5.3

perhaps this might help someone!

Return to “Plugin Development”