You are viewing an archive of Victory Road.
Victory Road closed on January 8, 2018. Thank you for making us a part of your lives since 2006! Please read this thread for details if you missed it.
During development of VictoryBattles, I came across a major problem: VBulletin stores its themes in very complex ways, but does keep its style sheet static in a separate cell. I found that it would be too complicated to use the SQL, so instead I used the CSS, interpreted it, and reprinted it as such. After doing so, I was able to properly render things.
The function I wrote to do this is:
function parseStyles($css,$winLineEndings = false) {
if ($winLineEndings) {
$end = "\r\n";
}
else {
$end = "\n";
}
$style = str_replace(array($end,"\t"),'',$css);
$style = preg_replace('/\<style(.*?)\>(.*?)\<\/style\>/is','$2',$style);
$style = preg_replace('/\<link(.+?)\/\>/is','',$style);
$style = preg_replace('/\/\*(.*?)\*\//is','',$style);showing me how
$values = array();
preg_match_all('/(.+?)[\s\n]?\{[\s\t\n]?(.+?)[\s\n]?\}/', $style, $matches);
foreach($matches[0] AS $i=>$original) {
foreach(explode(';', $matches[2][$i]) AS $attr) {
// Allows missing end semicolon.
if (strlen($attr) > 0) {
list($name, $value) = explode(': ', $attr);
foreach(explode(',', $matches[1][$i]) AS $attr2) {
$results[trim($attr2)][trim($name)] = trim($value);
$results[trim($attr2)][trim($name)] = trim($value);
}
}
}
}
return $results;
}
$style = @mysql_fetch_assoc(@mysql_query('SELECT css FROM style WHERE styleid = ' . $user['styleid']));
$style = $style['css'];
$data = parseStyles($style,true);
|
May we will use this for next chat release much better than my static way.(i didn't know where vb kept the styles.) Besides you codes a little more elegant. I relly don't know reg expressions good thing I got a perl class coming up.
|