Anri-chan/Source/df.php

From SDA Knowledge Base

< Anri-chan‎ | Source
Revision as of 09:50, 18 July 2007 by B'man (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

<?php // Settings $df_path = 'http://speeddemosarchive.com/kb/index.php/DF'; // Path to sda/kb/DB $titles_path = 'dfnd_titles.bat'; // Path where the titles file will be written $data_path = 'dfnd_data.bat'; // Path where the data file will be written // Usually non-editable stuff below. // If this doesn't work, comment it out and use the commented code below it. $raw = file_get_contents($df_path); /* ob_start(); include $df_path; $raw = ob_get_contents(); ob_clean(); */ $pos1 = strpos($raw, '<table>'); $pos2 = strpos($raw, '</table>'); if ( ($pos1 === false) or ($pos2 === false) or ($pos1 > $pos2) ) die('DF data does not exist in this page.'); $raw = substr($raw, $pos1, $pos2 - $pos1 - 1); $t = explode('<tr><td>', $raw); $k = 0; for ($i = 1; $t[$i]; $i++) { $t2 = substr( $t[$i], strpos($t[$i], '</td>') ); if ( preg_match('/D([14])/', $t2, $m) ) $data[$k]['d'] = $m[1]; if ( preg_match('/F([123])/', $t2, $m) ) $data[$k]['f'] = $m[1]; if ( preg_match('/([23])D/', $t2, $m) ) $data[$k]['twod'] = ($m[1] == 2) ? 'y' : 'n'; if ( is_array($data[$k]) ) { $title[$k] = str_replace( array( ':', '&', '<', '>', '(', ')', 'é' ), array( ' -', 'and', '[', ']', '[', ']', 'e' ), html_entity_decode( substr( $t[$i], 0, strpos($t[$i], '</td>') ) ) ); $initial[$k] = strtolower($title[$k]{$j}); if ($initial[$k] == '.') $initial[$k] = 'd'; // because .hack disagrees with Spock's philosophy. $k++; } } if (!is_array($title)) die('DF data does not exist in this page.'); $out1 = $out2 = "@ECHO OFF\r\n"; for ($i = 0; $title[$i]; $i++) { if ($initial[$i] == $cur_initial) $j++; else { $j = 1; $cur_initial = $initial[$i]; if ($out1) $out1 .= ")\r\n"; $out1 .= "IF [%dfnd_letter%]==[$cur_initial] (\r\n"; } $number[$i] = sprintf('%03d', $j); $title[$i] = preg_replace('/[:&|><\(\)]/', '^\\0', $title[$i]); $out1 .= "ECHO {$initial[$i]}{$number[$i]}: {$title[$i]}\r\n"; $out2 .= "IF [%s%]==[{$initial[$i]}{$number[$i]}] (\r\nCALL :out_info Selected \"{$title[$i]}\"\r\n"; foreach ($data[$i] as $k => $v) $out2 .= "SET $k=$v\r\n"; $out2 .= "SET dfnd_set=y\r\n)\r\n"; } $out1 .= ')'; if ( $f = fopen($titles_path, 'w' ) ) if ( fwrite( $f, $out1 ) ) print 'DF title file created successfully.<br/>'; if ( $f = fopen($data_path, 'w' ) ) if ( fwrite( $f, $out2 ) ) print 'DF data file created successfully.<br/>';

Personal tools