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

📄 util.php

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

	$query="select value from {$GLOBALS['fc_config']['db']['pref']}thatstack where thatid=$thatid order by id desc limit $offset,1";


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

}

/**
* Get the previous thing the client said
*
* Retrieve the entire previous input of the user from the dstore table.
* 
* @global integer
* 
* @return string         The previous input of the user. 
*/
function getinput($index){

	global $uid;

	$offset=1;

	$query="select value from {$GLOBALS['fc_config']['db']['pref']}dstore where uid='$uid' and name='input' order by id desc limit $index,$offset";

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

}

/**
* Take the user input and do all substitutions and split it into sentences
*
* The matching process searches a match for every sentence and in the end combines all 
* those individual matches into one reply. This funtion splits the sentences of the user's
* input, replaces the words that need to be subtituted (found in startup.xml).
* 
* 
* @global array contractsearch
* @global array contractreplace
* @global mixed abbrevsearch             not used in this function
* @global mixed removepunct              used in this function, but code is commented out.
* @global array likeperiodsearch
* @global array likeperiodreplace
* @global array aftersearch
* @global array afterreplace
* @global integer replacecounter
*
* @param string $input                   The unchanged user input.
*
* @return array                          each individual sentence, ready for matching. 
*/
function normalsentences($input){
	
	global $contractsearch,$contractreplace,$abbrevsearch,$abbrevreplace,$removepunct,$likeperiodsearch,$likeperiodreplace,$aftersearch,$afterreplace,$replacecounter;
	require_once "botinst/subs.inc";
	
	$cfull=$input;

	$cfull=preg_replace($contractsearch,$contractreplace,$cfull);
	
	$cfull=str_replace($aftersearch,$afterreplace,$cfull);	

	$replacecounter=1;
	$aftersearch=array();
	$afterreplace=array();

	//$cfull=str_replace($removepunct,"",$cfull);
	$cfull=str_replace($likeperiodsearch,$likeperiodreplace,$cfull);

	$newsentences=array();

	// Now split based on .'s
	$cfulls=split("\.",$cfull);

	for ($x=0;$x<sizeof($cfulls);$x++){
		if (trim($cfulls[$x])==""){

		}
		else {
			$newsentences[]=$cfulls[$x];
		}
	}

	return $newsentences;
}


/**
* Reverse the gender of a phrase
*
* Replaces, for example, 'he' in the string to 'she'. The gender related words and phrases that are used
* can be found in subs.inc and originally in the startup.xml
*
* @global array gendersearch
* @global array genderreplace
* @global array 
* @global array 
* @global integer
*
* @param string $input           The string where the gender related words/phrases need to be replaced
* 
* @return string                 The string containing where the gender related words have been replaced.
*/
function gender($input){

	global $gendersearch,$genderreplace,$aftersearch,$afterreplace,$replacecounter;
	require_once "botinst/subs.inc";
	
	$newinput=preg_replace($gendersearch,$genderreplace,$input);

	$newinput=str_replace($aftersearch,$afterreplace,$newinput);
	
	$replacecounter=1;
	$aftersearch=array();
	$afterreplace=array();

	return $newinput;

}

/** 
* Do a first to third person replacement
*
* Replaces, for example, "I was" to "he or she was". he gender related words and phrases that are used
* can be found in subs.inc and originally in the startup.xml
* 
* @global array firstthirdsearch
* @global array firstthirdreplace
* @global array
* @global array
* @global array
* @global array
* @global integer
*
* @param string $input           The string where the first->third related words/phrases need to be replaced
* 
* @return string                 The string containing where the first->third related words have been replaced.
*/
function firstthird($input){

	global $firstthirdsearch,$firstthirdreplace,$aftersearch,$afterreplace,$contractsearch,$contractreplace,$replacecounter;
	require_once "botinst/subs.inc";
	
	$newinput=preg_replace($firstthirdsearch,$firstthirdreplace,$input);

	$newinput=str_replace($aftersearch,$afterreplace,$newinput);
	
	$replacecounter=1;
	$aftersearch=array();
	$afterreplace=array();

	return $newinput;

}

/**
* Do a first to second person replacement
*
* Replaces, for example, "with you" to "with me". he gender related words and phrases that are used
* can be found in subs.inc and originally in the startup.xml
*
* @global array
* @global array
* @global array
* @global array
* @global integer
*
* @param string $input           The string where the first->second related words/phrases need to be replaced
* 
* @return string                 The string containing where the first->second related words have been replaced.
*/
function firstsecond($input){

	global $firstsecondsearch,$firstsecondreplace,$aftersearch,$afterreplace,$replacecounter;
	require_once "botinst/subs.inc";
	
	$newinput=preg_replace($firstsecondsearch,$firstsecondreplace,$input);

	$newinput=str_replace($aftersearch,$afterreplace,$newinput);
	
	$replacecounter=1;
	$aftersearch=array();
	$afterreplace=array();

	return $newinput;

}

/**
* Insert gossip into the database
*
* Gossip is an AIML tag where the user can store bits of information from one user and then
* reuse is in the conversation of another user. It is the only tag that behaves this way. Stores
* value into the gossip table of the database.
*
* @param string $gossip          The string that needs to be saved.
*
* @return void                   Nothing.
*/
function insertgossip($gossip){

	global $selectbot;

	$gossip=addslashes($gossip);

	$query="insert into {$GLOBALS['fc_config']['db']['pref']}gossip (gossip,bot) values ('$gossip'," . $selectbot . ")";
	$selectcode = mysql_query($query);
	if ($selectcode){
	}

}

/**
* Get the child nodes of the XML tree
*
* Retrieve the child nodes of the XML tree. This is a recursive function.
*
* @uses GetChildren()
* 
* @param array $vals               
* @param integer &$i                  call-by-reference variable for, most likely, GetXMLTree()
*
* @return array                       The child nodes in an array.
*/
function GetChildren($vals, &$i) { 

	$children = array(); 
	
	if (isset($vals[$i]['value'])) 
		array_push($children, $vals[$i]['value']); 

	while (++$i < count($vals)) { 
		
	if (!isset($vals[$i]['attributes'])){
		$vals[$i]['attributes']="";
	}
	if (!isset($vals[$i]['value'])){
		$vals[$i]['value']="";
	}
	
		switch ($vals[$i]['type']) { 
			case 'cdata': 
			array_push($children, $vals[$i]['value']); 
			break; 
		
			case 'complete': 
			array_push($children, array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'value' => $vals[$i]['value'])); 
			break; 
			
			case 'open': 
			array_push($children, array('tag' => $vals[$i]['tag'],'attributes' => $vals[$i]['attributes'], 'children' => GetChildren($vals,$i))); 
			break; 

			case 'close': 
			return $children; 
		} 
	} 
} 

/**
* Get an XML tree
*
* Create an XML tree in array form from a large string. 
*
* @uses GetChildren()
*
* @param string $data               Large string that needs to be turned into XML data.
*
* @return array                     Multi dimensional array in an XML way containing XML data.
*/
function GetXMLTree($data) { 

	$p = xml_parser_create(); 
	xml_parser_set_option($p,XML_OPTION_CASE_FOLDING,0);
	
	xml_parse_into_struct($p, $data, $vals, $index); 
	xml_parser_free($p); 

	$tree = array(); 
	$i = 0; 

	if (!isset($vals[$i]['attributes'])){
		$vals[$i]['attributes']="";
	}

	array_push($tree, array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'children' => GetChildren($vals, $i))); 
	return $tree; 

} 

/**
* Start a timer
*
* Save the start time of the to be timed script
* 
* @global array ss_timing_start_times          contains the start moments of the script
*
* @param string $name                          default value is 'default' Makes it possibe to time more than
*                                              event in one script.
*
* @return void                                 nothing
*/
function ss_timing_start ($name = 'default') {
    global $ss_timing_start_times;
    $ss_timing_start_times[$name] = explode(' ', microtime());
}

/**
* Stop a timer
*
* Save the stop time of the to be timed script
* 
* @global array ss_timing_stop_times          contains the stop moments of a script
*
* @param string $name                          default value is 'default' Makes it possibe to time more than
*                                              event in one script.
*
* @return void                                 nothing
*/
function ss_timing_stop ($name = 'default') {
    global $ss_timing_stop_times;
    $ss_timing_stop_times[$name] = explode(' ', microtime());
}

/**
* Retrieve timer data
*
* Get the running time the timed script
* 
* @global array ss_timing_start_times          contains the start and finish moments of the script
* @global array ss_timing_stop_times          contains the stop moments of a script
*
* @param string $name                          default value is 'default' Makes it possibe to time more than
*                                              event in one script.
*
* @return string                                the formated running time of the timed stript.
*/
function ss_timing_current ($name = 'default') {
    global $ss_timing_start_times, $ss_timing_stop_times;
    if (!isset($ss_timing_start_times[$name])) {
        return 0;
    }
    if (!isset($ss_timing_stop_times[$name])) {
        $stop_time = explode(' ', microtime());
    }
    else {
        $stop_time = $ss_timing_stop_times[$name];
    }
    // do the big numbers first so the small ones aren't lost
    $current = $stop_time[1] - $ss_timing_start_times[$name][1];
    $current += $stop_time[0] - $ss_timing_start_times[$name][0];
    return $current;
}

/**
* Change the case of the keys of an array to all uppercase
*
* Array keys can be number or strings. If strings then it's a good habit to use only uppercase. 
* This is sadly not always the case. This function makes sure that they are.
*
* @param array              Array suspected of having mixed case array keys.
*
* @return array             Array containing only uppercase array keys.
*/
function upperkeysarray($testa){
	
	$newtesta=$testa;
	if (is_array($testa)){
		$newtesta=array();
		$newkeys=array_keys($testa);
		for ($x=0;$x<sizeof($newkeys);$x++){
			$newtesta[strtoupper($newkeys[$x])]=$testa[$newkeys[$x]];
		}
	}
	return $newtesta;

}

/**
* Check to see if a tag is a custom tag.
*
* Program E supports additional, non AIML 1.0x specified, custom tags. This function checks to see if 
* the encountered XML tag is indeed a custom AIML tag. If it is a custom tag, it will then the
* appropriate function to use in &$functicall.
*
* @global array cttags            contains all the custom tags. Array is created by loadcustomtags()
*
* @see loadcustomtags()
* 
* @param string $tagname          name of the tag to be checked
* @param &$functocall             call-by-reference variable used to send back the function name that
*                                 needs to be called to process the tag's contents.
* 
* @return boolean				  true/false
*/
function iscustomtag($tagname,&$functocall){

	global $cttags;

	if (in_array(strtoupper($tagname),$cttags)){
		$functocall="ct_" . $tagname;
		return true;
	}
	else {
		return false;
	}

}

/**
* Load all custom tags
*
* Create a global accessible array with all custom tags, based upon the custom tag functions (ct_FunctionName()).
*
* @see customtags.php
*
* @return void 
*/
function loadcustomtags(){

	global $cttags;
	$cttags=array();

	$definedfuncs = get_defined_functions();
	$definedfuncs=$definedfuncs["user"];

	// find all funcs in ["user"] funcs that match ct_??? and register each function and tag name
	foreach($definedfuncs as $x){
		if (substr($x,0,3)=="ct_"){
			$cttags[]=strtoupper(substr($x,3,strlen($x)));
		}
	}

}

/**
* Look up the bot's ID number
*
* From the bot's name, retrieve it's bot ID number from the bots table in the database. This
* funtion requires that each bot has a uniqe name to function.
*
* @param string $botname                The bot's name.
*
* @return integer                       The bot ID that belongs to the unique botname.
*/
function lookupbotid($botname){

	$name=addslashes($botname);
    $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"];
        }
    }
	return -1;

}


/**
* Which bot is selected
*
* Returns the bit of SQL query that limits the results to the selected bot.
* 
* @global string selectbot              The currently selected bot. The bot the user is chatting to.
*
* @return string                        The bit of SQL query that limits the results to the selected bot.
*/
function whichbots()
{
	global $selectbot;

	return "bot=$selectbot";
}

?>

⌨️ 快捷键说明

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