Location: PHPKode > projects > Program E > docs/developer/__filesource/fsource_Interpreter__pluginscustomtags.php.html
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos  -->
			<title>File Source for customtags.php</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
											</head>
		<body>
						
<h1>Source for file customtags.php</h1>
<p>Documentation is available at <a href="../Interpreter/_plugins_customtags_php.html">customtags.php</a></p>
<div class="src-code">
<pre><ol><li><a name="a1"></a><span class="src-php">&lt;?</span></li>
<li><a name="a2"></a>&nbsp;</li>
<li><a name="a3"></a><span class="src-comm">/*</span></li>
<li><a name="a4"></a><span class="src-comm">    Program E</span></li>
<li><a name="a5"></a><span class="src-comm">    Copyright 2002, Paul Rydell</span></li>
<li><a name="a6"></a>    </li>
<li><a name="a7"></a><span class="src-comm">    This file is part of Program E.</span></li>
<li><a name="a8"></a>    </li>
<li><a name="a9"></a><span class="src-comm">    Program E is free software; you can redistribute it and/or modify</span></li>
<li><a name="a10"></a><span class="src-comm">    it under the terms of the GNU General Public License as published by</span></li>
<li><a name="a11"></a><span class="src-comm">    the Free Software Foundation; either version 2 of the License, or</span></li>
<li><a name="a12"></a><span class="src-comm">    (at your option) any later version.</span></li>
<li><a name="a13"></a>&nbsp;</li>
<li><a name="a14"></a><span class="src-comm">    Program E is distributed in the hope that it will be useful,</span></li>
<li><a name="a15"></a><span class="src-comm">    but WITHOUT ANY WARRANTY; without even the implied warranty of</span></li>
<li><a name="a16"></a><span class="src-comm">    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></li>
<li><a name="a17"></a><span class="src-comm">    GNU General Public License for more details.</span></li>
<li><a name="a18"></a>&nbsp;</li>
<li><a name="a19"></a><span class="src-comm">    You should have received a copy of the GNU General Public License</span></li>
<li><a name="a20"></a><span class="src-comm">    along with Program E; if not, write to the Free Software</span></li>
<li><a name="a21"></a><span class="src-comm">    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span></li>
<li><a name="a22"></a><span class="src-comm">*/</span></li>
<li><a name="a23"></a>&nbsp;</li>
<li><a name="a24"></a>&nbsp;</li>
<li><a name="a25"></a><span class="src-doc">/**</span></li>
<li><a name="a26"></a><span class="src-doc"> * Custom tags</span></li>
<li><a name="a27"></a><span class="src-doc"> * </span></li>
<li><a name="a28"></a><span class="src-doc"> * Contains functions that process custom, non-AIML 1.0.x specified tags</span></li>
<li><a name="a29"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@author</span><span class="src-doc"> Paul Rydell</span></li>
<li><a name="a30"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@copyright</span><span class="src-doc"> 2002</span></li>
<li><a name="a31"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@version</span><span class="src-doc"> 0.0.8</span></li>
<li><a name="a32"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@package</span><span class="src-doc"> Interpreter</span></li>
<li><a name="a33"></a><span class="src-doc"> */</span></li>
<li><a name="a34"></a>&nbsp;</li>
<li><a name="a35"></a>&nbsp;</li>
<li><a name="a37"></a><span class="src-comm">/*</span></li>
<li><a name="a38"></a><span class="src-comm">INSTRUCTIONS</span></li>
<li><a name="a39"></a>&nbsp;</li>
<li><a name="a40"></a><span class="src-comm">If you want to put custom tags into your templates you need to define functions to handle those tags in this file.</span></li>
<li><a name="a41"></a>&nbsp;</li>
<li><a name="a42"></a><span class="src-comm">Define the function with the name ct_customtagname. Setup the function to be passed the parameters $xmlnode, $inputstar, $thatstar, and $topicstar.</span></li>
<li><a name="a43"></a>&nbsp;</li>
<li><a name="a44"></a><span class="src-comm">After the function has been defined it will automatically be called to handle XML that matches your custom tag name.</span></li>
<li><a name="a45"></a>&nbsp;</li>
<li><a name="a46"></a><span class="src-comm">Please review the examples below.</span></li>
<li><a name="a47"></a>&nbsp;</li>
<li><a name="a48"></a><span class="src-comm">*/</span></li>
<li><a name="a49"></a>&nbsp;</li>
<li><a name="a50"></a>&nbsp;</li>
<li><a name="a51"></a><span class="src-comm">/*</span></li>
<li><a name="a52"></a><span class="src-comm">Example:</span></li>
<li><a name="a53"></a><span class="src-comm">You want to build email capabilities into the bot and have invented an &lt;email&gt; tag.</span></li>
<li><a name="a54"></a><span class="src-comm">Example of how your new email tag will be used:</span></li>
<li><a name="a55"></a><span class="src-comm">    &lt;category&gt;</span></li>
<li><a name="a56"></a><span class="src-comm">      &lt;pattern&gt;EMAIL PAUL AND TELL HIM *&lt;/pattern&gt;</span></li>
<li><a name="a57"></a><span class="src-comm">      &lt;template&gt;Okay. I emailed him. &lt;email to=&quot;hide@address.com&quot;&gt;&lt;star/&gt;&lt;/email&gt;&lt;/template&gt;</span></li>
<li><a name="a58"></a><span class="src-comm">    &lt;/category&gt;</span></li>
<li><a name="a59"></a><span class="src-comm">*/</span></li>
<li><a name="a60"></a>&nbsp;</li>
<li><a name="a61"></a><span class="src-comm">/*</span></li>
<li><a name="a62"></a><span class="src-comm">function ct_email($xmlnode,$inputstar,$thatstar,$topicstar){</span></li>
<li><a name="a63"></a>    </li>
<li><a name="a64"></a><span class="src-comm">    // Capitalize the attributes</span></li>
<li><a name="a65"></a><span class="src-comm">    $mynode=upperkeysarray($xmlnode[&quot;attributes&quot;]);</span></li>
<li><a name="a66"></a>&nbsp;</li>
<li><a name="a67"></a><span class="src-comm">    // Get the value of an attribute</span></li>
<li><a name="a68"></a><span class="src-comm">    $sendto=$mynode[&quot;TO&quot;];</span></li>
<li><a name="a69"></a>    </li>
<li><a name="a70"></a><span class="src-comm">    // Process everything inside the tag</span></li>
<li><a name="a71"></a><span class="src-comm">    $emailcontent=recursechildren(realchild($xmlnode),$inputstar,$thatstar,$topicstar);</span></li>
<li><a name="a72"></a>&nbsp;</li>
<li><a name="a73"></a><span class="src-comm">    // Send an email</span></li>
<li><a name="a74"></a><span class="src-comm">    mail($sendto, &quot;E-Mail from Program E&quot;, $emailcontent);</span></li>
<li><a name="a75"></a>&nbsp;</li>
<li><a name="a76"></a><span class="src-comm">    // Don't return anything to the output</span></li>
<li><a name="a77"></a><span class="src-comm">    return &quot;&quot;;</span></li>
<li><a name="a78"></a>&nbsp;</li>
<li><a name="a79"></a><span class="src-comm">}</span></li>
<li><a name="a80"></a><span class="src-comm">*/</span></li>
<li><a name="a81"></a>&nbsp;</li>
<li><a name="a82"></a><span class="src-comm">/*</span></li>
<li><a name="a83"></a><span class="src-comm">Example:</span></li>
<li><a name="a84"></a><span class="src-comm">You want to build math capabilities into the bot and have invented an &lt;add&gt; tag.</span></li>
<li><a name="a85"></a><span class="src-comm">Example of how your new add tag will be used:</span></li>
<li><a name="a86"></a><span class="src-comm">    &lt;category&gt;</span></li>
<li><a name="a87"></a><span class="src-comm">      &lt;pattern&gt;PLEASE ADD * TO *&lt;/pattern&gt;</span></li>
<li><a name="a88"></a><span class="src-comm">      &lt;template&gt;The answer is &lt;add&gt;&lt;star index=&quot;1&quot;/&gt;,&lt;star index=&quot;2&quot;/&gt;&lt;/add&gt;&lt;/template&gt;</span></li>
<li><a name="a89"></a><span class="src-comm">    &lt;/category&gt;</span></li>
<li><a name="a90"></a><span class="src-comm">*/</span></li>
<li><a name="a91"></a>&nbsp;</li>
<li><a name="a92"></a><span class="src-comm">/*</span></li>
<li><a name="a93"></a><span class="src-comm">function ct_add($xmlnode,$inputstar,$thatstar,$topicstar){</span></li>
<li><a name="a94"></a>    </li>
<li><a name="a95"></a><span class="src-comm">    $total=0;</span></li>
<li><a name="a96"></a>&nbsp;</li>
<li><a name="a97"></a><span class="src-comm">    # Process everything inside the tag</span></li>
<li><a name="a98"></a><span class="src-comm">    $numberstoadd=recursechildren(realchild($xmlnode),$inputstar,$thatstar,$topicstar);</span></li>
<li><a name="a99"></a>&nbsp;</li>
<li><a name="a100"></a><span class="src-comm">    # Split the numbers into an array</span></li>
<li><a name="a101"></a><span class="src-comm">    $numberstoadd=split(&quot;,&quot;,$numberstoadd);</span></li>
<li><a name="a102"></a>&nbsp;</li>
<li><a name="a103"></a><span class="src-comm">    # Total up the numbers</span></li>
<li><a name="a104"></a><span class="src-comm">    foreach($numberstoadd as $x)</span></li>
<li><a name="a105"></a><span class="src-comm">        $total += $x;</span></li>
<li><a name="a106"></a>&nbsp;</li>
<li><a name="a107"></a><span class="src-comm">    # Return the answer</span></li>
<li><a name="a108"></a><span class="src-comm">    return $total;</span></li>
<li><a name="a109"></a>&nbsp;</li>
<li><a name="a110"></a><span class="src-comm">}</span></li>
<li><a name="a111"></a><span class="src-comm">*/</span></li>
<li><a name="a112"></a>&nbsp;</li>
<li><a name="a113"></a><span class="src-php">?&gt;</span></li>
</ol></pre>
</div>
	<p class="notes" id="credit">
		Documentation generated on Wed, 12 Jan 2005 12:24:45 +0100 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.3.0RC3</a>
	</p>
	</body>
</html>
Return current item: Program E