\$txt
"); return Keep(str_replace(array('$file', '$txt', '$rank'), array($file, $txt, $rank), $FortuneFmt)); } function FortuneFilter($pagename, $opt, &$file, &$txt, &$rank) { $file = basename($file); $txt = htmlspecialchars($txt, ENT_NOQUOTES); } function FortuneAdage($datfile, $rank = -1) { if(!$datfile) return ''; $datfp = @fopen($datfile, "rb"); if(!$datfp) return "cannot open index $datfile"; FortuneReadLong($datfp); // Just move over the first long. Might as well be fseek. $rank = ($rank < 0) ? mt_rand(0, FortuneReadLong($datfp) - 1) : min($rank, FortuneReadLong($datfp) - 1); fseek($datfp, 24 + 4 * $rank); $offset = FortuneReadLong($datfp); fclose($datfp); $file = substr($datfile, 0, -4); $fp = @fopen($file, "rb"); if(!$fp) return "cannot open $file"; fseek($fp, $offset); $lines = array(); while($line = fgets($fp, 1024)) { if($line[0] == "%") break; $lines[] = $line; } fclose($fp); return array($file, implode('', $lines), $rank); } function FortuneReadLong($fp) { $res = fread($fp, 4); return ord($res[3]) + (ord($res[2]) << 8) + (ord($res[1]) << 16) + (ord($res[0]) << 24); } #function FortuneWriteLong($fp, $l) { # fwrite($fp, chr(($l >> 24) & 255)); # fwrite($fp, chr(($l >> 16) & 255)); # fwrite($fp, chr(($l >> 8) & 255)); # fwrite($fp, chr(($l) & 255)); #} #function FortuneCreateIndexFile($file) { # $fp = @fopen($file, "r"); # if(!$fp) { echo "cannot open $file"; exit; } # $i = 1; # $length = 0; # $longest = 0; # $shortest = 100000; # $indices[0] = 0; # while(!feof($fp)) { # $line = fgets($fp); # if($line == "%\n") { # $indices[$i] = ftell($fp); # $i++; # if($length > $longest) $longest = $length; # if($length < $shortest) $shortest = $length; # $length = 0; # } # else $length = $length + strlen($line); # } # fclose($fp); # $fp = @fopen("{$file}.dat", "w"); # if($fp == false) { echo "could not write to file..."; exit; } # // Write header. # FortuneWriteLong($fp, 2); # FortuneWriteLong($fp, count($indices)); # FortuneWriteLong($fp, $longest); # FortuneWriteLong($fp, $shortest); # FortuneWriteLong($fp, 0); # FortuneWriteLong($fp, 37 << 24); # for($i = 0; $i < count($indices); $i++) FortuneWriteLong($fp, $indices[$i]); # fclose($fp); #}