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