Documentation is available at common.inc.php
- <?php
- /*
- Program E related AIML knowledgebase tools
- Copyright 2004, Anne Kootstra [anne@aiml.info]
- http://www.AIML.info
- Program E is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- Program E is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Program E; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- /**
- * Make REQUEST variables in to regular variables.
- *
- * Retrieves REQUEST variables (POST/GET) and turns them into regular variables
- * If the REQUEST variable doesn't exist, it creates the variables with the
- * default value that's also passed with it.
- *
- * @param string $param REQUEST variable name
- * @param string $default default value in case variable doesn't exist
- *
- * @return void It creates a set of variables.
- *
- */
- function getRequest($param, $default)
- {
- global $$param;
- if (!IsSet($$param))
- {
- if (!IsSet($_REQUEST[$param]))
- {
- $$param = $default;
- }
- else
- {
- $$param = $_REQUEST[$param];
- }
- }
- }
- /**
- * Load template file from template folder.
- *
- *Template function. Retrieves the template from the templates folder.
- *
- * @param string $TPL Name of the HTML template file.
- *
- * @return string Template file contents for the to be retuned page.
- *
- */
- function getTemplate($TPL)
- {
- $TEMPLATE='templates/' . $TPL . '.html';
- if ($fh =fopen($TEMPLATE,'r'))
- {
- $contents = fread($fh,filesize($TEMPLATE));
- fclose ($fh);
- return $contents;
- }
- }
- /**
- * Replace placeholders in template file with array elements.
- *
- * Template function. Takes an array of values, and the name of the template
- * and replaces the placeholders with their array equivilent values.
- *
- * @uses getTemplate()
- *
- * @param string $TPL Name of the HTML template file.
- * @param array $ARRAY The array where the key is the placeholder
- * name and the value what it needs to be replaced
- * with.
- *
- * @return string The HTML code for the to be retuned page.
- */
- function useTemplate($TPL,$ARRAY)
- {
- $html = strtr(getTemplate($TPL),$ARRAY);
- return preg_replace("/(\{{)(\w+)(\}})/",'\\2',$html);
- }
- /**
- * Get the chatterbots names from table
- *
- * Retrieve an array with the botnames and their ID's from the bots table
- *
- * @return array Array-key is the botid, Array-value the botname
- */
- function getbotnames() {
- /**
- * @var array
- */
- $availbots=array();
- // Get all the names of our bots.
- $query="select id, botname from bots";
- $selectcode = mysql_query($query);
- if ($selectcode){
- if(!mysql_numrows($selectcode)){
- return '';
- }
- else{
- while ($q = mysql_fetch_array($selectcode)){
- $availbots[$q[0]]=$q[1];
- }
- return $availbots;
- }
- }
- }
- /**
- * Print debug message.
- *
- * This function is called at strategic places in the code. Uncommenting the
- * the print command will activate the 'debugger' mode.
- *
- * @param string $msg The message you'd like to have printed.
- * @param interger $val Not used for anything.
- *
- * @return void Prints to HTML
- *
- */
- function debugger($msg,$val)
- {
- #print "$msg\n";
- }
- /**
- * Get the first bot ID from the table.
- *
- * @uses debugger()
- *
- * Retrieves the bot's ID, from the bots table.
- * WARNING: This is expected NOT to work in a multi-bot environment.
- *
- * @return integer The bot's ID.
- *
- */
- function findbotid(){
- $query = "select id from bots order by id desc limit 0,1";
- debugger($query,2);
- $selectcode = mysql_query($query);
- if ($selectcode){
- if(!mysql_numrows($selectcode)){
- return "";
- }
- else{
- while ($q = mysql_fetch_array($selectcode)){
- return $q[0];
- }
- }
- }
- return "";
- }
- /**
- * Retrieve the Main Node ID.
- *
- * The main node is the start-node of the AIML tree, the trunk if you will.
- * This node often contains the word <input> and the parent reference is
- * always the bot's ID, only negative. Thus, making sure that it doesn't
- * conflict with parent ID's of AIML categories.
- *
- * @uses debugger()
- *
- * @param integer $botid The bot's ID.
- *
- * @return integer The pattern ID of the main node.
- *
- */
- function findmainnode($botid){
- $query = "select id from patterns where (word='<input>' or word is null) and parent=-".$botid."";
- debugger($query,2);
- $selectcode = mysql_query($query);
- if ($selectcode){
- if(!mysql_numrows($selectcode)){
- return "";
- }
- else{
- while ($q = mysql_fetch_array($selectcode)){
- return $q[0];
- }
- }
- }
- return "";
- }
- /**
- * Get the parent ID.
- *
- * Retrieve the corresponding parent ID (i.e. the next word's pattern ID) for
- * this pattern ID.
- *
- * @param integer $patternID The word's pattern ID.
- *
- * @return integer The corresponding Parent ID.
- *
- */
- function findParent($patternID){
- $query = "select parent from patterns where id ='".$patternID."'";
- //debugger($query,2);
- $selectcode = mysql_query($query);
- if ($selectcode){
- if(!mysql_numrows($selectcode)){
- return "";
- }
- else{
- while ($q = mysql_fetch_array($selectcode)){
- return $q[0];
- }
- }
- }
- return "";
- }
- /**
- * Check if template ID exists.
- *
- * Check to see if a specific template ID is found in the templates tables.
- *
- * @param integer $templateID The category's ID.
- *
- * @return boolean TRUE/FALSE.
- *
- */
- function templateCheck($templateID) {
- $query = "select if(count(id) = 0, 'FALSE', 'TRUE') as template_exist from templates where id = '".$templateID."'";
- //debugger($query,2);
- $selectcode = mysql_query($query);
- if ($selectcode){
- if(!mysql_numrows($selectcode)){
- return "";
- }
- else{
- while ($q = mysql_fetch_array($selectcode)){
- return $q[0];
- }
- }
- }
- return "";
- }
- ?>
Documentation generated on Tue, 11 Jan 2005 18:41:03 +0100 by phpDocumentor 1.3.0RC3