95 lines
5.7 KiB
PHP
95 lines
5.7 KiB
PHP
<?php
|
|
|
|
if (isset($_GET["FileName"]))
|
|
$FileName = $_GET["FileName"];
|
|
|
|
echo "<div align='left'>
|
|
<table border='0'><tr><td><img src='images/transparent.gif' alt='' class='icon_4' /></td><td><h1>fortune.php tutorial</h1></td></tr></table>
|
|
<ol>
|
|
<li><a href='#history'>Brief history of fortune</a></li>
|
|
<li><a href='#fonc'>How it works</a></li>
|
|
<li><a href='#adapt'>PHP version</a></li>
|
|
<li><a href='#limit'>Limitations</a></li>
|
|
<li><a href='#utilisation'>Usage</a></li>
|
|
<li><a href='#packages'>Fortune cookies files available in this website</a></li>
|
|
<li><a href='/'>Back to menu</a></li>
|
|
</ol>";
|
|
?>
|
|
|
|
<br />
|
|
|
|
<h2><a name='history'>1.Brief history of fortune</a></h2>
|
|
<p>The fortune program has been written under NetBSD, one of the numerous Unix clones. It displays a random quote from one or more files. It has been ported under Linux, then as its source code became more generic, under other platforms, like SunOS 4.x for example.</p>
|
|
<p>For more information about fortune's history, do a <i>man fortune</i> on your favorite Un*x system!</p>
|
|
<br />
|
|
|
|
<h2><a name="fonc">2.How it works</a></h2>
|
|
<p>Every "bunch" of quotes is split into two files: a text file containing the quotes themselves, separated by a special character, usually %.
|
|
Since version 1.4, an index file with .dat extension containing pointers to each quote is added to the text file.</p>
|
|
<p>In fact, fortune reads a .dat file and take a random reference, wich contains the position of the corresponding quote, and then use this reference to get and display the quote.
|
|
This speeds up greatly selection from big files (several thousands of quotes)</p>
|
|
<p>.dat files are automaticaly generated by the strfile program, provided by the fortune package.</p>
|
|
<p>Note that fortune is not just for quotes, you can also use it to display informations, adverts, etc.!</p>
|
|
<br />
|
|
|
|
<h2><a name="adapt">3.PHP version</a></h2>
|
|
<p>Original and PHP versions works the same way: randomly take a quote file, then select a quote in the index file, and eventually display the corresponding quote.</p>
|
|
<p>Options works also the same way: without parameter, fortune.php selects a random quote from all available files; with a file name in parameter, the quote will be extracted from this file only.</p>
|
|
<p>The quote is displayed in raw mode, without any decoration. According to your mood, you can add effects, colors, etc.</p>
|
|
<br />
|
|
|
|
<h2><a name="limit">4.Limitations</a></h2>
|
|
<p>The strfile program used to produce index files has not been ported in PHP. You still have to use the original program for indexing.</p>
|
|
<p>Original fortune program provides multiples options, like a specific drawing (like 20% for file quotes1 and 80% for file quotes2), or to display "offending" quotes separatly...None of these options have been ported. In fact only basic functions are supported: random drawing from a specified file, or from all files. I wanted to avoid overloads in the PHP code, and this way get a faster script. But if you think you can improve it, it's up to you!!</p>
|
|
<br />
|
|
|
|
<h2><a name="utilisation">5.Usage</a></h2>
|
|
<p>Insert the following code in a PHP page to display a random quote on your website:</p>
|
|
<table width="100%" border="0" bgcolor="#f0f0f0"><tr><td>
|
|
<?php<br />include("http://tourmentine.com/modules/fortune.php");<br />?>
|
|
</td></tr></table>
|
|
<br /><br />
|
|
<p>If you provide a file name as a parameter, quotes will be extracted from this file.<br />
|
|
Use the following syntax in this case:</p>
|
|
<table width="100%" border="0" bgcolor="#f0f0f0"><tr><td>
|
|
<?php<br />$FileName="Name_of_File";<br />include("http://tourmentine.com/modules/fortune.php");<br />?>
|
|
</td></tr></table>
|
|
<br /><br />
|
|
<p>You can also use it in simple HTML link:</p>
|
|
<table width="100%" border="0" bgcolor="#f0f0f0"><tr><td>
|
|
<a href="http://tourmentine.com/modules/fortune.php?FileName=Pensees">Click here to display the quote of the day</a>
|
|
</td></tr></table>
|
|
<br /><br />
|
|
<p>Or via JavaScript (in your start page for example ;). Be careful, the script's name is not the same:</p>
|
|
<table width="100%" border="0" bgcolor="#f0f0f0"><tr><td>
|
|
<script language="javascript" src="http://tourmentine.com/scripts/fortune.js"></script>
|
|
</td></tr></table>
|
|
<br />
|
|
<table width="100%" border="0" bgcolor="#f0f0f0"><tr><td>
|
|
<script language="javascript" src="http://tourmentine.com/scripts/fortune.js?FileName=tolkien_fr"></script>
|
|
</td></tr></table>
|
|
<br />
|
|
|
|
<h2><a name="packages">6.Fortune cookies files available in this website</a></h2>
|
|
<p><b>Note</b>: All files below are in French, but it's very easy to find fortunes in <a href='http://www.google.fr/search?q=fortunes'>English or other languages</a>.</p>
|
|
<p>Click on a file's filename to display a random quote in a new window, or click on <b>download</b> to download an archive (you can extract it with <a href='http://www.gzip.org' target='_blank'>gzip/tar</a>, <a href='http://www.winzip.com' target='_blank'>WinZip</a>, or <a href='http://www.powerarchiver.com' target='_blank'>PowerArchiver</a>) containing the quotes file and its .dat file. Once extracted, these files can be used by both fortune program and fortune.php script.</p>
|
|
<br />
|
|
<ul>
|
|
<?php
|
|
|
|
$d = opendir("modules/fortunes/");
|
|
|
|
while (false!==($file = readdir($d)))
|
|
if (!strchr($file,"."))
|
|
echo "<li><a href=\"modules/fortune.php?FileName=$file\" target=\"_blank\">".$file."</a> <a href=\"http://ftp.tourmentine.com/fortunes_fr/$file.tar.gz\">(download)</a></li>\n";
|
|
|
|
closedir($d);
|
|
?>
|
|
</ul>
|
|
<br />
|
|
<br />
|
|
</div>
|
|
<?php
|
|
echo "<div align='right'><h6>(Updated ".date("M j Y",filemtime(__FILE__)).")</h6></div><br />";
|
|
echo "<br />";
|
|
?>
|