⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 botloaderfuncs.php

📁 flashget43的源代码 一个比较常用的下载程序
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php

/*
    Program E
    Copyright 2002, Paul Rydell
    Portions by Jay Myers
    
    This file is part of Program E.
    
    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
*/

/**
 * AIML loading functions
 * 
 * Contains contains the functions for the actual loading of AIML.
 * @author Paul Rydell
 * @copyright 2002
 * @version 0.0.8
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @package Loader
 */


/**
* The general preferences and database details.
*/

require_once "dbprefs.php";

global $selectbot, $annesID, $is_single;			


/**
* Deletes everything about a bot.
*
* Empties the tables, bot, patterns, templates, bots and gmcache
*
* @param integer $bot             The bot's ID
*
* @return void
*/
function deletebot($bot)		
{
	
	$q="delete from {$GLOBALS['fc_config']['db']['pref']}bot where bot=$bot";	
    $e = mysql_query($q);
    if ($e){
    }
    $q="delete from {$GLOBALS['fc_config']['db']['pref']}patterns where bot=$bot";	
    $e = mysql_query($q);
    if ($e){
    }
    $q="delete from {$GLOBALS['fc_config']['db']['pref']}templates where bot=$bot";
    $e = mysql_query($q);
    if ($e){
    }
    $q="delete from {$GLOBALS['fc_config']['db']['pref']}bots where id=$bot"; 
    $e = mysql_query($q);
    if ($e){
    }
    $q="delete from {$GLOBALS['fc_config']['db']['pref']}gmcache";			
    $e = mysql_query($q);
    if ($e){
    }


}

/**
* Deletes information about a bot in the cache and bot tables.
*
* Used by the incremental bot loader program so it doesn't wipe out the whole 
* bot on each aiml file load. Deletes everything in bot, bots and gmcache tables.
* 
* @param integer $bot             The bot's ID.
*
* @return void
*/

// 
// 
function deletejustbot($bot){			

	$q="delete from {$GLOBALS['fc_config']['db']['pref']}bots where id=$bot"; 
    $e = mysql_query($q);
    if ($e){
    }
	$q="delete from {$GLOBALS['fc_config']['db']['pref']}bot where bot=$bot";	
	$e = mysql_query($q);
	if ($e){
	}
    $q="delete from {$GLOBALS['fc_config']['db']['pref']}gmcache";			
    $e = mysql_query($q);
    if ($e){
    }

}

/** 
* Deletes the gmcache table. 
*
* This needs to be called whenever the patterns or templates table is updated.
*
* @return void
*/
function flushcache()
{
    $q="delete from {$GLOBALS['fc_config']['db']['pref']}gmcache";			
    $e = mysql_query($q);
    if ($e){
    }
}

/**
* Makes the keys of an array uppercase.
*
* Makes the keys of an array uppercase.
*
* @param array $testa           The array where the keys need to be changed into uppercase.
*
* @return array                 An array with only uppercase keys.
*/
if(!function_exists('upperkeysarray'))
{
function upperkeysarray($testa)
{
   	$newtesta=array();
    $newkeys=array_keys($testa);
    for ($x=0;$x<sizeof($newkeys);$x++){
   	    $newtesta[strtoupper($newkeys[$x])]=$testa[$newkeys[$x]];
   	}
    return $newtesta;
}
}
/**
* Write the substitution include file
*
* Write the substitution arrays back into the subs.inc
*
* @global object                 The opened subs.inc file, ready to write to. 
*
* @param string $string          most likely an array or all arrays turned into a big file.
*
* @return void
*/
function addtosubs($string)
{

    global $fp;

	if( $fp ) fwrite($fp,$string);

}

/** 
* Create the object for writing the substitution include file
*
* Creates the object, which is then used by addtosubs() to write to
*
* @see addtosubs()
* @see makesubscode()
* @global object
*
* @return void
*/
function createsubfile()
{

    global $fp;

    $fp = @fopen ("subs.inc", "w+");

}

/**
* Find a word in the patterns table given the word and the parent.
*
* The AIML patterns are stored in the MySQL table in a binary tree format. 
* This function retrieves the next word details based upon the previous' word's ID. 
* If this word doesn't exist it returns 0, else it returns it's details.
*
* @uses setnotend()
*
* @param string $word             The word that is to be searched
* @param integer $parent          The ID of the parent word
* 
* @return integer                 The ID of the word that was searched
*/
function findwordid($word,$parent)
{

    $word=addslashes($word);
    $query="select id,isend from {$GLOBALS['fc_config']['db']['pref']}patterns where word='$word' and parent=$parent";	

    $selectcode = mysql_query($query);
    if ($selectcode){
        if(!mysql_numrows($selectcode)){
            return 0;
        }
        else{
            while ($q = mysql_fetch_array($selectcode)){
                
                if ($q[1]==1){
                    setnotend($q[0]);
                }

                return $q[0];
            }
        }
    }
}

/**
* Find a wildcard in the patterns table given the word and the parent.
*
* Similar as findwordid() but this will retrieve the ID if there is a wildcard that fits.
*
* @uses setnotend()
*
* @param string $word             The word that is to be searched, either _ or *
* @param integer $parent          The ID of the parent word
* 
* @return integer                 The ID of the word that was searched
*/
function findwordidstar($word,$parent)
{

    if ($word=="*"){
        $val=3;
    }
    elseif ($word=="_"){
        $val=1;
    }
    $query="select id,isend from {$GLOBALS['fc_config']['db']['pref']}patterns where parent=$parent and word is null and ordera=$val";	
    
    $selectcode = mysql_query($query);
    if ($selectcode){
        if(!mysql_numrows($selectcode)){
            return 0;
        }
        else{
            while ($q = mysql_fetch_array($selectcode)){
                
                if ($q[1]==1){
                    setnotend($q[0]);
                }
                
                return $q[0];
            }
        }
    }
}


/**
* Set an entry in the patterns table to not be flagged as the last word in its context.
*
* Update a record in the patterns table, change isend column from 1 to 0. Given a particular word ID.
* 
* @param integer $wordid
*
* @return void
*/
function setnotend($wordid)
{

    $query="update {$GLOBALS['fc_config']['db']['pref']}patterns set isend=0 where id=$wordid";
    $q=mysql_query($query);
    if ($q){

    }

}

/**
* Inserts the pattern into the patterns table.
*
* inserts the pattern, that and topic as individual words in binary tree format into the patterns table
* 
* @uses findwordid()
* @uses insertwordpattern()
* @uses findwordidstar()
*
* @global string
* @global integer
*
* @param string $mybigsentence          Contains the pattern, that and topic in the following format <input>word word<that>word word<topic>word word.
*/
function insertmysentence($mybigsentence)
{
    global $selectbot, $annesID;		

    $sentencepart="";

    $newstarted=0;
    if($annesID != ""){
    $parent = $annesID;
    } else {
    $parent=-$selectbot;
    }

    //Parse into invidividual words
    //Use split
    $allwords=split(" ",$mybigsentence);
    $qadd="";
    for ($x=0;$x<sizeof($allwords)+1;$x++){

        // Last word in context
        $lwic=0;

        if ($x==sizeof($allwords)){
            $word="";
        }
        else {
            $word=$allwords[$x];
        }
        
        if (strtoupper($word)=="<INPUT>"){
            $sentencepart="INPUT";
        } elseif (strtoupper($word)=="<THAT>"){
            $sentencepart="THAT";
        } elseif (strtoupper($word)=="<TOPIC>"){
            $sentencepart="TOPIC";
        }
        
        // Find out if it is the last word in its context
        if ($x==(sizeof($allwords)-1)){
            $lwic=1;
        }
		// Prevent some warnings by checking this first.
		elseif (($x+1) >= (sizeof($allwords))){
		
		}
        elseif ((strtoupper($allwords[$x+1])=="<THAT>") || (strtoupper($allwords[$x+1])=="<TOPIC>")){
            $lwic=1;
        }
        
        if (($word!="*")&&($word!="_")){

            if ($newstarted!=1){
                $wordid=findwordid($word,$parent);
            }
            
            if (($wordid!=0) && ($newstarted!=1)){
                $parent=$wordid;
            }
            else {
                
                $newstarted=1;

                $sword=addslashes($word);
                $qadd="($selectbot, null,'$sword',2,$parent,$lwic)";	

				$parent = insertwordpattern($qadd);
		


            }
        }
        elseif (($word=="*")||($word=="_")){

            if ($newstarted!=1){            
                $wordid=findwordidstar($word,$parent);
            }
            
            if (($wordid!=0) && ($newstarted!=1)){
                $parent=$wordid;
            }
            else {
                
                $newstarted=1;

                if ($word=="*"){
                    $val=3;
                }
                elseif ($word=="_"){
                    $val=1;
                }

                $qadd="($selectbot, null,null,$val,$parent,$lwic)";	

				$parent = insertwordpattern($qadd);


				
            }
        }
    }

    return $parent;

}

/**
* Inserts an entry into the patterns table. Returns the ID of the new row inserted.
*
* insert a word into the patterns table, returns the id of the record so it can be 
* used as the parent ID of the next word that's to be inserted.
*
* @param string $qadd                 The word of the pattern to be inserted
*
* @return integer                     The record ID of the inserted word.
*/
function insertwordpattern($qadd)
{
	$query="insert into {$GLOBALS['fc_config']['db']['pref']}patterns(bot,id,word,ordera,parent,isend) values $qadd";
	$qcode=mysql_query($query);
	if ($qcode){

		return mysql_insert_id();
	}
	
}

/**
* Inserts a template into the template table.
*
* Insert the template into the template database. <br/>
* This version has been adapted to also insert the pattern, that and topic into the additionally added columns 
*
* @uses templateexists()
*
* @global integer
* @global integer              The ID of the record in the patterns table that links to this table
* @global string               The pattern, including variables like _ and *.
* @global string               the topic, including variable like _ and *
* @global string               the that, including variables like _ and *
*
* @param integer $idused       The ID of the record in the patterns table that links to the template table.
* @param string $template      The contents inbetween <template/> tags. 
*
* @return void
*/

$templBuf = array();
function insertmytemplate($idused,$template, $flushlast=false)
{
	
	global $selectbot,$templatesinserted, $pattern, $topic, $that, $templBuf, $is_single;
    
    //if (!templateexists($idused))
	{
        $templatesinserted++;

        $template=addslashes($template);
		$pattern=addslashes($pattern);
		
		$templBuf[] = "($selectbot, $idused,'$template','$pattern','$that','$topic')";
		
		if( sizeof($templBuf) >= 200 || $is_single)
		{
			$query="insert IGNORE into {$GLOBALS['fc_config']['db']['pref']}templates (bot,id,template,pattern,that,topic) values " . implode(',', $templBuf) ;	
			$qcode=mysql_query($query);
        	if ($qcode)
			{
        	}
			//unset($templBuf);
			$templBuf = array();
		}        
		
        
    }

}

/**
* Checks if a template exists for a given pattern
*
* Does a query on the database to see if an ID is used by a template in the templates table.
*
* @param integer $idused         The ID number that corresponds to the number in the ID column, if it exists.
*
* @return boolean                true/false
*/
$templBuf2 = array();
function templateexists($idused)
{
/*
	return true;
	global $templBuf2;
	if( isset($templBuf2[$idused]) ) return true;
	else { $templBuf2[$idused]=1; return false;} */
	
	return false;
/*
    $query="select id from {$GLOBALS['fc_config']['db']['pref']}templates where id=$idused";

    $qcode=mysql_query($query);

    if ($qcode){
        if(!mysql_numrows($qcode)){
            return false;
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -