Advertisement:

Author Topic: [Trick] Auto Code Live Links  (Read 7267 times)

Offline Masterd

  • SMF Hero
  • ******
  • Posts: 3,895
  • Gender: Male
[Trick] Auto Code Live Links
« on: January 04, 2011, 07:47:11 AM »
This is now packaged as a mod. 

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

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

SMF 2.0

Sources/Subs.php

Find:

Code: [Select]
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:

Code: [Select]
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.
« Last Edit: January 27, 2011, 07:05:34 AM by Masterd »

Offline Masterd

  • SMF Hero
  • ******
  • Posts: 3,895
  • Gender: Male
Re: [Trick] Auto Code Live Links
« Reply #1 on: January 04, 2011, 08:22:16 AM »
Can someone move this to the Tips and Tricks board?

Offline rakicko

  • Full Member
  • ***
  • Posts: 418
  • Gender: Male
  • Have fun!
    • http://
Re: [Trick] Auto Code Live Links
« Reply #2 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
Code: [Select]
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
« Last Edit: January 05, 2011, 07:17:40 AM by rakicko »

Offline Masterd

  • SMF Hero
  • ******
  • Posts: 3,895
  • Gender: Male
Re: [Trick] Auto Code Live Links
« Reply #3 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?

Offline lucas-ruroken

  • SMF Hero
  • ******
  • Posts: 4,907
  • Gender: Male
  • Adk Developer
    • lucas.ruroken on Facebook
    • lucasruroken on GitHub
Re: [Trick] Auto Code Live Links
« Reply #4 on: January 09, 2011, 01:47:25 AM »
good tip ;)
Adk Portal 3.1 is coming....

Design your universe!

Offline Mick.

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,853
  • Gender: Male
    • idesignSMF on Facebook
    • @idesign360 on Twitter
    • idesignSMF.com
Re: [Trick] Auto Code Live Links
« Reply #5 on: January 09, 2011, 02:15:07 AM »
Cool man ;)

Offline Masterd

  • SMF Hero
  • ******
  • Posts: 3,895
  • Gender: Male
Re: [Trick] Auto Code Live Links
« Reply #6 on: January 09, 2011, 07:43:31 AM »
Thanks! :D

Offline Masterd

  • SMF Hero
  • ******
  • Posts: 3,895
  • Gender: Male
Re: [Trick] Auto Code Live Links
« Reply #7 on: January 10, 2011, 07:07:55 AM »
I modified the code in the first post. Problem with different font is solved.

Offline Masterd

  • SMF Hero
  • ******
  • Posts: 3,895
  • Gender: Male
Re: [Trick] Auto Code Live Links
« Reply #8 on: January 27, 2011, 07:03:45 AM »

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,313
    • StoryBB/StoryBB on GitHub
Re: [Trick] Auto Code Live Links
« Reply #9 on: January 27, 2011, 12:25:12 PM »
You should make it work on iurl tags as well.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Masterd

  • SMF Hero
  • ******
  • Posts: 3,895
  • Gender: Male
Re: [Trick] Auto Code Live Links
« Reply #10 on: January 27, 2011, 12:26:27 PM »
I will do that just after I add the support for custom boards.

Offline Masterd

  • SMF Hero
  • ******
  • Posts: 3,895
  • Gender: Male
Re: [Trick] Auto Code Live Links
« Reply #11 on: February 04, 2011, 01:33:43 PM »
Can someone finally move this topic?

Offline Masterd

  • SMF Hero
  • ******
  • Posts: 3,895
  • Gender: Male
Re: [Trick] Auto Code Live Links
« Reply #12 on: February 06, 2011, 03:37:46 PM »
Can someone finally move this topic?