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

📄 botloaderfuncs.php

📁 flashget43的源代码 一个比较常用的下载程序
💻 PHP
📖 第 1 页 / 共 3 页
字号:
    return true;
*/
}

/**
* Called by the XML parser that is parsing the startup.xml file.
*
* startS and endS are two functions that cooperate. startS looks for the start of an XML tag, endS for the end tag.
* It fills the global variabls with info to be processed further on. Inserts the bots into the bots table, inserts the bot predicates into its respective table.
*
* @todo Find out what Global $areinc does
*
* @uses upperkeysarray()
* @uses botexists()
* @uses getbotid()
* @uses deletebot()
*
* @global integer
* @global string
* @global array
* @global array                  contains the splitter characters which are used to split the sentences. For example period, comma, semi-colon, exclamation mark, question mark.
* @global array                  contains the input, split into sentences
* @global array                  contains the gender words or phrases.
* @global array                  contains the person words or phrases
* @global array                  contains the person2 words or phrases
* @global array                  contains the names of all the bots, or their ID's
* @global array                  contains something unknown
*
* @param resource $parser        SAX XML resource handler
* @param string $name            name of the encountered tag.
* @param array $attrs            contains the additional attribues of a tag, like value, id, find.
* 
* @return void
*/
function startS($parser,$name,$attrs)
{

    global $selectbot, $whaton, $startupwhich, $splitterarray, 
    $inputarray, $genderarray, $personarray, $person2array, $allbots, $areinc;
    
    $attrs=upperkeysarray($attrs);

    if (strtoupper($name)=='LEARN') {
        $whaton = 'LEARN';
    }
    if (strtoupper($name)=="GENDER"){
        $startupwhich="GENDER";
    }
    elseif (strtoupper($name)=="INPUT"){
        $startupwhich="INPUT";
    }
    elseif (strtoupper($name)=="PERSON"){
        $startupwhich="PERSON";
    }
    elseif (strtoupper($name)=="PERSON2"){
        $startupwhich="PERSON2";
    }

    if (strtoupper($name)=="PROPERTY"){
        $q="insert into {$GLOBALS['fc_config']['db']['pref']}bot (bot,name,value) values ($selectbot,'" . addslashes($attrs["NAME"]) . "','" . addslashes($attrs["VALUE"]) . "')";	

        $qcode=mysql_query($q);
        if ($qcode){
        }

    }
    elseif (strtoupper($name)=="BOT") {					
		$bot = $attrs["ID"];					
		if (botexists($bot)){
			$existbotid = getbotid($bot);
			if ($areinc==1){
				deletebot($existbotid);	
			}
		}

		$asbot=addslashes($bot);
		$q="insert into {$GLOBALS['fc_config']['db']['pref']}bots (id,botname) values (null,'$asbot')";	
		$qcode=mysql_query($q);
		
		if ($areinc==1){
			if ($qcode){
			}
			$newbotid=mysql_insert_id();
		}
		else {
			$newbotid=$existbotid;
		}

		$selectbot=$newbotid;
		$allbots[]=$selectbot;

		#print "<b>Loading bot: $bot ($selectbot)<BR></b>\n";	
		flush();							
    }
    elseif (strtoupper($name)=="SPLITTER"){
        $splitterarray[]=$attrs["VALUE"];
    }
    elseif (strtoupper($name)=="SUBSTITUTE"){
        if (trim($attrs["FIND"])!=""){
            if ($startupwhich=="INPUT"){
                $inputarray[]=array($attrs["FIND"],$attrs["REPLACE"]);
            }
            elseif ($startupwhich=="GENDER"){
                $genderarray[]=array($attrs["FIND"],$attrs["REPLACE"]);
            }
            elseif ($startupwhich=="PERSON"){
                $personarray[]=array($attrs["FIND"],$attrs["REPLACE"]);
            }
            elseif ($startupwhich=="PERSON2"){
                $person2array[]=array($attrs["FIND"],$attrs["REPLACE"]);
            }
        }
    }
}

/** 
* Called by the XML parser that is parsing the startup.xml file.
*
* @global string                 Which start tag was processed last
* 
* @param resource $parser        SAX XML resource handler
* @param string $name            name of the encountered tag.
*
* @return void
*/
function endS($parser,$name)
{
    global $whaton;
    if (strtoupper($name)=='LEARN') {
        $whaton = '';
    }
}

/** 
* Process contents <learn> tag in startup.xml
*
* Called by the XML parser that is parsing the startup.xml file. * -> all files in directory, or single file.
* 
* @todo When using * it should process AIML in subdirectories too. This is currently only supported by using multiple <learn> tag entries for every folder containing AIML files.
*
* @uses learnallfiles()
*
* @global string
* @global array       contains the AIML files to learn.         
* @global integer     
*
* @param resource $parser        SAX XML resource handler
* @param string $data            assuming it contains the path to the file.
*/
function handlemeS($parser, $data)
{
    global $whaton, $learnfiles, $selectbot;
    if (strtoupper($whaton)=="LEARN"){
        if (trim($data)=="*"){
            learnallfiles($selectbot);        
        }
        else {
			$learnfiles[$selectbot][]=trim($data);
        }
    
    }
}

/**
* Checks if a bot already exists.
*
* Does a check to see if a bot with a particular name already exists. The reliance on unique names if crucial for the bot to work.
*
* @param string $name            the name of the bot that is checked.
*
* @return boolean                true/false
*/
function botexists($name){

    // search to get existing id
	$name=addslashes($name);
    $q="select id from {$GLOBALS['fc_config']['db']['pref']}bots where botname='$name'";
    $selectcode = mysql_query($q);
    if ($selectcode) {
        while ($q = mysql_fetch_array($selectcode)){
			return true;
        }
    }

    return false;

}

/**
* Gets a bot's property value.
*
* Retrieves the value of a particular bot predicate. If the predicate isn't set, then it will return the value 'default'. This has been hardcoded
* 
* 
* @global integer
* 
* @param string $name        the name of the bot predicate to be retrieved.
*
* @return string             the value of the bot predicate.
*/
function getbotvalue($name)
{
    global $selectbot;	

    $q="select value from {$GLOBALS['fc_config']['db']['pref']}bot where name=" . addslashes($name) . " and bot=$selectbot";	

    $selectcode = mysql_query($q);
    if ($selectcode){
        if(!mysql_numrows($selectcode)){
                return DEFAULTPREDICATEVALUE;
        }
        else{
            while ($q = mysql_fetch_array($selectcode)){
                return $q["value"];
            }
        }
    }
}

/**
* Gets the ID of a bot given its name.
*
* Gets the ID of a bot given its name
*
* @todo move this function to a common include file shared by both the Loader and the Interpreter.
* 
* @param string $name              The name of the bot
*
* @ return integer                 The bot's ID.
*/
function getbotid ($name)
{
    // search to get existing id
	$name=addslashes($name);
    $q="select id from {$GLOBALS['fc_config']['db']['pref']}bots where botname='$name'";
    $selectcode = mysql_query($q);
    if ($selectcode) {
        while ($q = mysql_fetch_array($selectcode)){
                return $q["id"];
        }
    }

}

/**
* Used by the AIML XML parser
*
* Looks for the start tag used in AIML files for category, template, that, topic.
*
* @uses upperkeysarray()
* @uses getbotvalue()
*
* @global string                  which tag is being processed
* @global string
* @global string
* @global integer                 to indicate if recursion is allowed
* @global string                  the topic at hand in the AIML file
*
* @param resource $parser        SAX XML resource handler
* @param string $name            name of the encountered tag.
* @param array $attrs            contains the additional attribues of a tag, like value, id, find.
*
* @return void
*/
function startElement($parser, $name, $attrs) 
{
    global $whaton,$template,$pattern,$recursive,$topic;
	
	if (strtoupper($name)=="CATEGORY"){
        $whaton="CATEGORY";
    }
    elseif (strtoupper($name)=="TEMPLATE"){
        $whaton="TEMPLATE";
        $template="";
        $recursive=0;
    }
    elseif (strtoupper($name)=="PATTERN"){
        $whaton="PATTERN";
    }
    elseif ((strtoupper($name)=="THAT")&&(strtoupper($whaton)!="TEMPLATE")){
        $whaton="THAT";
    }
    elseif (strtoupper($name)=="TOPIC"){
        $whaton="TOPIC";
    }

    if ((strtoupper($whaton)=="PATTERN")&&(strtoupper($name)!="PATTERN")){


        if (strtoupper($name)=="BOT"){

            $attrs = upperkeysarray($attrs);
            $pattern .= getbotvalue($attrs["NAME"]);

        }
        else{
            $pattern .= "<$name";

            while (list ($key, $val) = each ($attrs)) {
                $pattern .= " $key=\"$val\" ";
            }

            $pattern .= ">";
        }

    }
    elseif ((strtoupper($whaton)=="TEMPLATE")&&(strtoupper($name)!="TEMPLATE")){
        
        $template .="<$name";

        while (list ($key, $val) = each ($attrs)) {
            $template .= " $key=\"$val\" ";
        }        

        $template .=">";
    }
    elseif (strtoupper($whaton)=="TOPIC"){

        $attrs = upperkeysarray($attrs);
        $topic=$attrs["NAME"];

    }
}

/**
* Used by the AIML XML parser
* 
* Looks for the end tags of 'topic' and 'category'.
*
* @uses insertmysentence()
* @uses insertmytemplate()
* 
* @global string                  which tag is being processed
* @global string
* @global string
* @global integer                 to indicate if recursion is allowed
* @global string                  the topic at hand in the AIML file
* @global string                  the that of the category.
*
* @param resource $parser        SAX XML resource handler
* @param string $name            name of the encountered tag.
*
* @return void
*/
function endElement($parser, $name) 
{

	global $whaton,$pattern,$template,$recursive,$topic,$that;
    
    if (strtoupper($name)=="TOPIC"){
        $topic="";
    }

    if (strtoupper($name)=="CATEGORY"){
        $template=trim($template);
        $topic=trim($topic);
        $that=trim($that);
        $pattern=trim($pattern);

        if ($that==""){
            $that="*";
        }
        if ($topic==""){
            $topic="*";
        }
        if ($pattern==""){
            $pattern="*";
        }

    
        $mybigsentence="<input> $pattern <that> $that <topic> $topic";
		
		$idused=insertmysentence($mybigsentence);
        
		insertmytemplate($idused,$template);

        // IIS doesn't flush properly unless it has a bunch of characters in it. This fills it with spaces.
		print "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ";
        flush();

        $pattern="";
        $template="";
        $that="";

    }
    else {
        if ((strtoupper($whaton)=="PATTERN")&&(strtoupper($name)!="PATTERN")){
            if (strtoupper($name)!="BOT"){
                $pattern .="</$name>";
            }
        }
        elseif ((strtoupper($whaton)=="TEMPLATE")&&(strtoupper($name)!="TEMPLATE")){
            $template .="</$name>";
        }    
    }

}


/**
* Part of the AIML XML parser.
* 
* Checks for start tags of pattern, topic, that, template and CDATA
*
* @global string
* @global string
* @global string
* @global string
* @global string
*
* @param resource $parser        SAX XML resource handler 
* @param string $data            containing what needs to be parsed, I guess. 
*
* @return void
*/
function handleme($parser, $data)
{
    global $whaton,$pattern,$template,$topic,$that;
    
    if (strtoupper($whaton)=="PATTERN"){
        $pattern .= $data;
    }
    elseif (strtoupper($whaton)=="TOPIC"){
        $topic .= $data;
    }
    elseif (strtoupper($whaton)=="THAT"){
        $that .= $data;
    }
    elseif (strtoupper($whaton)=="TEMPLATE"){
        $template .= $data;
    }
	elseif (strtoupper($whaton)=="TEMPLATE"){
		$template .= "<![CDATA[$data]]>";
	}
}


/**
* Parses startup.xml if the bot is loaded incrementally - one file at a time.
*
* Parses the startup.xml if the bot id loaded incrementally. One file at a time. This is very hacky and may not work properly.
*
* @uses learn()
* 
* @global string                 The root directory of the AIML files?
* @global array                  This array will hold the files to LEARN
* @global boolean                
* @global array                  Contains all the botnames.
* @global integer                contains the selected bot ID.
*
* @param integer $fileid         the ID of the file to be processed.
*/
function loadstartupinc($fileid){

	global $rootdir,$learnfiles,$areinc,$allbots,$selectbot;
	
	$areinc=0;

	if ($fileid==1){
		$areinc=1;
	}

	print "Loading startup.xml<BR>\n";
	$learnfiles = array(); # This array will hold the files to LEARN

	$file = $rootdir . "startup.xml";
	$xml_parser = xml_parser_create();
	xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0);
	xml_set_element_handler($xml_parser, "startS", "endS");
	xml_set_character_data_handler ($xml_parser, "handlemeS");
	if (!($fp = fopen($file, "r"))) {
		die("could not open XML input");
	}
	while ($data = fread($fp, 4096)) {
		if (!xml_parse($xml_parser, $data, feof($fp))) {
			die(sprintf("XML error: %s at line %d",
						xml_error_string(xml_get_error_code($xml_parser)),
						xml_get_current_line_number($xml_parser)));
		}
	}
	xml_parser_free($xml_parser);

	# For each of the bots learn all of the files

	$totalcounter=1;

	foreach ($allbots as $bot){

		# print "<b>Loading bot: $bot<BR></b>\n";	

	    $single_learnfiles = $learnfiles[$bot];
		$single_learnfiles = array_unique($single_learnfiles);

		foreach ($single_learnfiles as $file) {
			
			$selectbot=$bot;
			
			if ($totalcounter==$fileid){
				learn($file);
				return 0;
			}

			$totalcounter++;

		}
	}

	return 1;

⌨️ 快捷键说明

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