Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Masterd on January 04, 2011, 07:47:11 AM

Title: [Trick] Auto Code Live Links
Post by: Masterd on January 04, 2011, 07:47:11 AM
This is now packaged as a mod. 

http://custom.simplemachines.org/mods/index.php?mod=2881 (http://custom.simplemachines.org/mods/index.php?mod=2881)





I found an interesting mod request here:

http://www.simplemachines.org/community/index.php?topic=415773.0 (http://www.simplemachines.org/community/index.php?topic=415773.0)

So, I decided to share my code with you. This modification will turn every live link on your forum to a code.

SMF 1.1.x

For SMF 1.1.x use this mod:

http://custom.simplemachines.org/mods/index.php?mod=1724 (http://custom.simplemachines.org/mods/index.php?mod=1724)

SMF 2.0

Sources/Subs.php

Find:

array(
'tag' => 'url',
'type' => 'unparsed_content',
'content' => '<a href="$1" class="bbc_link new_win" target="_blank">$1</a>',
'validate' => create_function('&$tag, &$data, $disabled', '
$data = strtr($data, array(\'<br />\' => \'\'));
if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
$data = \'http://\' . $data;
'),
),
array(
'tag' => 'url',
'type' => 'unparsed_equals',
'before' => '<a href="$1" class="bbc_link new_win" target="_blank">',
'after' => '</a>',
'validate' => create_function('&$tag, &$data, $disabled', '
if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
$data = \'http://\' . $data;
'),
'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_after' => ' ($1)',
),


Replace with this:

array(
'tag' => 'url',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['code'] . ' <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div><code href="$1" class="bbc_code">$1</code>',
'validate' => create_function('&$tag, &$data, $disabled', '
$data = strtr($data, array(\'<br />\' => \'\'));
if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
$data = \'http://\' . $data;
'),
),
array(
'tag' => 'url',
'type' => 'unparsed_equals',
'before' => '<div class="codeheader">' . $txt['code'] . ' <a href="#" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div><code href="$1" class="bbc_code">',
'after' => '</code>',
'validate' => create_function('&$tag, &$data, $disabled', '
if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
$data = \'http://\' . $data;
'),
'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_after' => ' ($1)',
),


Screenshot is in the attachment.
Title: Re: [Trick] Auto Code Live Links
Post by: Masterd on January 04, 2011, 08:22:16 AM
Can someone move this to the Tips and Tricks board?
Title: Re: [Trick] Auto Code Live Links
Post by: rakicko on January 05, 2011, 07:07:36 AM
Masterd it looks good..and this is improved..but take a look this,but i have one wish..is there any way..when a people post a multible links.. like
link1,link2 etc..with this mod..i see line link1[code/][code]link2[code/] etc..and is there any way ..if there is a multiple links to become line
[code] link1
link2
[/code]

and the font is not like original.. take a look
Title: Re: [Trick] Auto Code Live Links
Post by: Masterd on January 05, 2011, 03:27:18 PM
I'm currently working on my laptop, so I will check this for you on Friday. Can someone move this?
Title: Re: [Trick] Auto Code Live Links
Post by: lucas-ruroken on January 09, 2011, 01:47:25 AM
good tip ;)
Title: Re: [Trick] Auto Code Live Links
Post by: Mick. on January 09, 2011, 02:15:07 AM
Cool man ;)
Title: Re: [Trick] Auto Code Live Links
Post by: Masterd on January 09, 2011, 07:43:31 AM
Thanks! :D
Title: Re: [Trick] Auto Code Live Links
Post by: Masterd on January 10, 2011, 07:07:55 AM
I modified the code in the first post. Problem with different font is solved.
Title: Re: [Trick] Auto Code Live Links
Post by: Masterd on January 27, 2011, 07:03:45 AM
This is now packaged as a mod.

http://custom.simplemachines.org/mods/index.php?mod=2881 (http://custom.simplemachines.org/mods/index.php?mod=2881)
Title: Re: [Trick] Auto Code Live Links
Post by: Arantor on January 27, 2011, 12:25:12 PM
You should make it work on iurl tags as well.
Title: Re: [Trick] Auto Code Live Links
Post by: Masterd on January 27, 2011, 12:26:27 PM
I will do that just after I add the support for custom boards.
Title: Re: [Trick] Auto Code Live Links
Post by: Masterd on February 04, 2011, 01:33:43 PM
Can someone finally move this topic?
Title: Re: [Trick] Auto Code Live Links
Post by: Masterd on February 06, 2011, 03:37:46 PM
Quote from: Masterd on February 04, 2011, 01:33:43 PM
Can someone finally move this topic?