blackdtools / Blackd-Proxy-CLASSIC

Blackd Proxy CLASSIC
MIT License
9 stars 7 forks source link

the latestchanges page is wayyyy out of date (v 26.5 last update) #63

Closed divinity76 closed 8 years ago

divinity76 commented 8 years ago

the latestchanges page at http://blackdtools.com/lastchanges.php is seriously out of date - currently listing changes up to version 26.5

i wrote a php script that will download the latest github version of frmNews.frm , parse the strMsg code that makes the news in-proxy, and make a html version of it, if you run it as a daily chron on your webhost, the changes page should never be more than ~24 hours out of date - as of writing, this code correctly parses everything from version 14.1 to 37.2 , so it probably won't break anytime soon..

<?php
$rawtext = file_get_contents('https://raw.githubusercontent.com/blackdtools/Blackd-Proxy-CLASSIC/master/frmNews.frm');

function tohtml($str)
{
    return htmlentities($str, ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
}
function parse_strMsg($text)
{
    $matches = array();
    $res     = preg_match('/(strMsg\s*=.*?)Me\.txtBoard/is', $text, $matches);
    assert($res === 1);
    $text       = $matches[1];
    //var_dump($res,$text);
    $text       = trim($text);
    $parsedText = '';
    $i          = 0;
    foreach (preg_split("/((\r?\n)|(\r\n?))/", $text) as $line) {
        ++$i;
        $line = trim($line);
        while (strlen($line) > 2) {
            if (stripos($line, 'vbCrLf') === 0) {
                $line = substr($line, strlen('vbCrLf'));
                $parsedText .= "\n";
                continue;
            }
            if ($line[0] === '"') {
                $line = substr($line, 1);
                $to   = stripos($line, '"');
                if ($to === false) {
                    var_dump($parsedText);
                    throw new LogicException('cannot find the end " in line ' . $i . ': ' . $line);
                }
                //var_dump("ADDING: ",substr($line,0,$to));
                $parsedText .= substr($line, 0, $to);
                $line = substr($line, $to + 1);
                //var_dump('FOO',$line);
                continue;
            }
            $line = substr($line, 1);
        }
    }
    //var_dump('"PARSED TEXT:',$parsedText);
    return $parsedText;
}
$parsedText = parse_strMsg($rawtext);
echo '<pre>' . tohtml($parsedText) . '</pre>';

goddam i have too much free time

blackdtools commented 8 years ago

Thank you! I will use it.

divinity76 commented 8 years ago

nice