Help get this bbcode working please?

I’ve been trying to integrate some code into my mod somehow, but I’m lost.
Everything I’ve tried breaks the forum…

I need my LMGTFY mod to not only point to lmgtfy, but to create and get its resultant url from tinyurl.

I’ve found this floating around the net:

<?php $url = "http://vijayjoshi.org"; $tiny = file_get_contents("http://tinyurl.com/api-create.php?url=$url"); echo 'Original url : '.$url; echo '<br/>'; echo '<br/>'; echo 'TinyURL (Click to test) : <a href="'.$tiny.'" target="_blank">'.$tiny.'</a>'; ?>

The LMGTFY mod can be found here: http://custom.simplemachines.org/mods/index.php?mod=2814

Here’s the latest I’m trying to get working:

This goes at the end of the Subs.php file:

function lmgtfy($string) { return file_get_contents("http://tinyurl.com/api-create.php?url=http://lmgtfy.com/?q=$string"); }

This goes in the lmgtfy bbc:

'content' => '<a href="' . lmgtfy($1) . '" class="bbc_link new_win" target="_blank">$1</a>',

or this:

'content' => '<a href="' . lmgtfy('$1') . '" class="bbc_link new_win" target="_blank">$1</a>',

The first ‘content’ code breaks the forum.
The second doesn’t break the forum. While it points to lmgtfy without issue, it only searches for $1 instead of the users input.

I’ve found some other code on the net as well.
If something like this will work better… :-\

function tinyUrl($url){ $tiny = 'http://tinyurl.com/api-create.php?url='; return file_get_contents($tiny.urlencode(trim($url))); }

I’ve VERY limited knowledge of PHP so any help is greatly appreciated… ;D

I am not familiar with this lmgtfy mod, but where did you get this code:
[php]‘content’ => ‘$1’,[/php]
?
Sure it breaks your forum, because $1 is not a valid variable name.
Was this code provided with mod?

I wrote the mod.
http://custom.simplemachines.org/mods/index.php?mod=2814

Like I said, it’s basically a rewrite of the default [ url ] bbcode.

If you have a look at the Subs.php file in its original state, you’ll see that the $1 is used for the default [ url ] tag.

I’m wanting to make it so my lmgtfy bbc return the tinyurl version of lmgtfy.com/?q=$1
So anyone clicking on the link sees only the tinurl link and not the lmgtfy link in their browser…

Also, as I said, this: 'content' => '<a href="' . lmgtfy('$1') . '" class="bbc_link new_win" target="_blank">$1</a>',

does NOT break the forum…

Sry, can’t edit posts for some reason…

This:'content' => '<a href="' . lmgtfy('$1') . '" class="bbc_link new_win" target="_blank">$1</a>',

and this:function lmgtfy($string) { return file_get_contents("http://tinyurl.com/api-create.php?url=http://lmgtfy.com/?q=$string"); }

Came from another member of a forum I frequent.
He’s got more experience with PHP, but can’t assist further for some reason…

Never mind…

I got it sorted with some help from a friend on another forum.

Here’s the result for anyone interested:

array( 'tag' => 'lmgtfy', 'type' => 'unparsed_content', 'content' => '$1', 'validate' => create_function('&$tag, &$data, $disabled', '$data = \'<a href="\' . file_get_contents("http://tinyurl.com/api-create.php?url=http://lmgtfy.com/?q=" . urlencode($data)) . \'" class="bbc_link new_win" target="_blank">\' . $data . \'</a>\';'), ), array( 'tag' => 'lmgtfy', 'type' => 'unparsed_equals', 'before' => '<a href="$1" class="bbc_link new_win" target="_blank">', 'after' => '</a>', 'validate' => create_function('&$tag, &$data, $disabled', '$data = file_get_contents("http://tinyurl.com/api-create.php?url=http://lmgtfy.com/?q=" . urlencode($data));'), 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), 'disabled_after' => ' ($1)', ),

Here’s the entire mod once again:
http://custom.simplemachines.org/mods/index.php?mod=2814

Sponsor our Newsletter | Privacy Policy | Terms of Service