This works well with
GoogleGroups Beta service. This helps make links to
GoogleGroups with text remotely extracted from usenet topic.
<?php
/**
* Copyright 2004 by Gyoung-Yoon Noh <nohmad at sub-port.net>
* All rights reserved. Distributable under GPL.
*
* $Id: UsenetMacro,v 1.13 2005/02/05 03:23:51 root Exp root $
*/
function macro_Usenet($formatter, $value)
{
global $DBInfo;
list($group, $thread) = @explode(':', $value);
$img = sprintf('<img src="%s/google-16.png" alt="GoogleGroups:"'.
' align="middle" hspace="1" />', $DBInfo->imgs_dir);
if ($group == 'http') {
$url = $value;
} else {
$url = 'http://groups-beta.google.com/group/'.$group;
if (preg_match('/[[:xdigit:]]+/', $thread))
$url .= '/browse_thread/thread/'.$thread;
else
$subj = $group;
}
if (!$subj) {
$purl = parse_url($url);
$fp = @fsockopen($purl['host'], 80, $errno, $errstr, 5);
$out = "GET {$purl['path']} HTTP/1.0\nHost: {$purl['host']}\n\n";
@fwrite($fp, $out);
$buf = @fgets($fp, 80);
if (!preg_match('@200 OK@i', $buf))
return '<!> URL is not found <!>';
while (strlen($buf) <= 25000) {
$_ = @fread($fp, 1024);
$buf .= $_;
if (strlen($_) < 1024) break;
}
fclose($fp);
$seek = strpos($buf, '<TR><TD>Subject: <b>') + 20;
$offset = strpos($buf, '</b></TD></TR>', $seek);
$subj = substr($buf, $seek, $offset-$seek);
if (!$subj) $subj = $group;
}
return sprintf('%s<a href="%s">%s</a>', $img, $url, $subj);
}
?>
Write like this,
[[Usenet(comp.lang.python)]]
[[Usenet(comp.lang.python:fec2ae850574adf4)]]
[[Usenet(http://groups-beta.google.com/group/comp.unix.programmer/browse_thread/thread/d302919d5af2b802)]]
then it will be displayed like...
Usenet
Usenet
Usenet