(2012-11-17, 03:10 AM)Seabody Wrote: I'm working on a plugin to try to integrate the WDtN Short URL API into a forum. If I finish it (mainly trying to figure out how the hell to insert the link into a template), I'll ask Eric/Euan/FMB/WDtN in general if I can release it. Meantime though, it's still hidden on my main site.
Update: I've managed to get everything to work right except for the final link - it's always throwing my testing "Unable to generate short link" error at me.
I don't see any problem with you releasing it
I made one for WeDesign after I set up the shortener. Here's the basic code behind it if you're needing help:
Hook: newthread_do_newthread_end
global $db, $mybb, $url, $tid;
$curl = curl_init('http://wdtn.co/api/shortener/create');
curl_setopt_array(
$curl,
array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 30,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array('url' => $mybb->settings['bburl'].'/'.$url),
)
);
$result = curl_exec($curl);
curl_close($curl);
$result = json_decode($result);
if (!$result->error) {
$db->update_query('threads', array('shortlink' => $db->escape_string($result->slug)), "tid = '". (int) $tid."'");
}
Then for WD I used a Laravel task file to iterate through old threads and generate a new shortlink. I don't seem to have that file anymore though. It was pretty simple to create.
Because of the use of JSON you'll have to make it clear the plugin is only for > PHP 5.2. Most people should be running versions newer than that though...