Difference between revisions of "Anri-chan/Source/df.php"
From SDA Knowledge Base
Ballofsnow (Talk | contribs) |
(grenola's and my changes) |
||
Line 1: | Line 1: | ||
− | <pre><nowiki><?php | + | <pre><nowiki> |
+ | <?php | ||
// Settings | // Settings | ||
$df_path = 'http://speeddemosarchive.com/kb/index.php/DF'; // Path to sda/kb/DB | $df_path = 'http://speeddemosarchive.com/kb/index.php/DF'; // Path to sda/kb/DB | ||
− | $titles_path = ' | + | $titles_path = 'dfnd_titles_temp.bat'; // Path where the titles file will be written |
− | $data_path = ' | + | $data_path = 'dfnd_data_temp.bat'; // Path where the data file will be written |
Line 23: | Line 24: | ||
if ( ($pos1 === false) or ($pos2 === false) or ($pos1 > $pos2) ) | 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); | $raw = substr($raw, $pos1, $pos2 - $pos1 - 1); | ||
Line 30: | Line 31: | ||
$k = 0; | $k = 0; | ||
− | for ($i = 1; | + | $ct = count($t); |
+ | for ($i = 1; $i < $ct; $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]{0}); | |
− | + | if ($initial[$k] == '.') $initial[$k] = 'd'; // because .hack disagrees with Spock's philosophy. | |
− | + | $k++; | |
− | + | } | |
} | } | ||
if (!is_array($title)) | if (!is_array($title)) | ||
− | + | die('DF data does not exist in this page.'); | |
$out1 = $out2 = "@ECHO OFF\r\n"; | $out1 = $out2 = "@ECHO OFF\r\n"; | ||
− | for ($i = 0; | + | $cur_initial = ''; |
+ | $ct = count($title); | ||
+ | for ($i = 0; $i < $ct; $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 .= ')'; | $out1 .= ')'; | ||
+ | $out_info = ' | ||
+ | GOTO :EOF | ||
+ | |||
+ | :out_info | ||
+ | ECHO %* | ||
+ | ECHO. | ||
+ | GOTO :EOF | ||
+ | '; | ||
+ | |||
+ | $out_info=str_replace("\n","\r\n",$out_info); | ||
+ | $out2 .= $out_info; | ||
if ( $f = fopen($titles_path, 'w' ) ) | if ( $f = fopen($titles_path, 'w' ) ) | ||
− | + | if ( fwrite( $f, $out1 ) ) | |
− | + | print 'DF title file created successfully.<br/>'; | |
− | + | ||
if ( $f = fopen($data_path, 'w' ) ) | if ( $f = fopen($data_path, 'w' ) ) | ||
− | + | if ( fwrite( $f, $out2 ) ) | |
− | + | print 'DF data file created successfully.<br/>'; | |
+ | </nowiki></pre> |
Latest revision as of 22:33, 2 August 2007
<?php // Settings $df_path = 'http://speeddemosarchive.com/kb/index.php/DF'; // Path to sda/kb/DB $titles_path = 'dfnd_titles_temp.bat'; // Path where the titles file will be written $data_path = 'dfnd_data_temp.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; $ct = count($t); for ($i = 1; $i < $ct; $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]{0}); 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"; $cur_initial = ''; $ct = count($title); for ($i = 0; $i < $ct; $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 .= ')'; $out_info = ' GOTO :EOF :out_info ECHO %* ECHO. GOTO :EOF '; $out_info=str_replace("\n","\r\n",$out_info); $out2 .= $out_info; 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/>';