コード例 #1
0
/**
* Handles the actual XML between the <template/> tags.
*
* Recognises the different tags, access the different functions to process each individual tag. Notes by the original developer: <br/>
* Why isn't this a huge switch statement? Because it has to do more comlicated checking than just string comparison to figure out what it should do. <br/>
* How can I organize this better? Good question.
*
* @todo It seems to me that this function could modelled similarly to the custom tag system. Where there is a seperate function for each tag.
*
* @uses getid()
* @uses getfdate()
* @uses getsize()
* @uses upperkeysarray()
* @uses debugger()
* @uses recursechildren()
* @uses respond()
* @uses botget()
* @uses gender()
* @uses getinput()
* @uses bset()
* @uses insertgossip()
* @uses firstthird()
* @uses firstsecond()
* @uses getthat()
* @uses realchild()
*
* @param mixed $xmlnode               Getting either a string or an array from recursechildren() func.
* @param array $inputstar             If a matched pattern includes *'s then what is covere by the * is found here.
* @param array $thatstar              if a used that contains a star, then what is covered by the * is found here.
* @param array $topicstar             if a used topic contains a star, then what is covered by the * is found here.
*
* @return string                      The bot's response.
*/
function handlenode($xmlnode, $inputstar, $thatstar, $topicstar)
{
    if (!is_array($xmlnode)) {
        return $xmlnode;
    } elseif (strtoupper($xmlnode["tag"]) == "ID") {
        return getid();
    } elseif (strtoupper($xmlnode["tag"]) == "DATE") {
        //		return getfdate(); // deprecated
        $mynode = upperkeysarray($xmlnode["attributes"]);
        // Get the value of an attribute
        $date_format = $mynode["FORMAT"];
        return getfdate($date_format);
    } elseif (strtoupper($xmlnode["tag"]) == "VERSION") {
        return PROGRAMEVERSION;
    } elseif (strtoupper($xmlnode["tag"]) == "SIZE") {
        return getsize();
    } elseif (strtoupper($xmlnode["tag"]) == "STAR") {
        $mynode = upperkeysarray($xmlnode["attributes"]);
        //$starindex=$xmlnode["attributes"]["INDEX"];
        if (!(is_array($mynode) && isset($mynode["INDEX"]))) {
            $mynode["INDEX"] = "";
        }
        $starindex = $mynode["INDEX"];
        if ($starindex == "") {
            $starindex = "1";
        }
        debugger("starindex: {$starindex}", 3);
        //print_r($inputstar);
        return $inputstar[$starindex - 1];
    } elseif (strtoupper($xmlnode["tag"]) == "THATSTAR") {
        $mynode = upperkeysarray($xmlnode["attributes"]);
        //$starindex=$xmlnode["attributes"]["INDEX"];
        if (!(is_array($mynode) && isset($mynode["INDEX"]))) {
            $mynode["INDEX"] = "";
        }
        $starindex = $mynode["INDEX"];
        if ($starindex == "") {
            $starindex = "1";
        }
        debugger("starindex: {$starindex}", 3);
        //print_r($inputstar);
        return $thatstar[$starindex - 1];
    } elseif (strtoupper($xmlnode["tag"]) == "TOPICSTAR") {
        $mynode = upperkeysarray($xmlnode["attributes"]);
        //$starindex=$xmlnode["attributes"]["INDEX"];
        if (!(is_array($mynode) && isset($mynode["INDEX"]))) {
            $mynode["INDEX"] = "";
        }
        $starindex = $mynode['INDEX'];
        if ($starindex == "") {
            $starindex = "1";
        }
        debugger("starindex: {$starindex}", 3);
        //print_r($inputstar);
        return $topicstar[$starindex - 1];
    } elseif (strtoupper($xmlnode["tag"]) == "SRAI") {
        // Build up a new response inside of here (using recursechildren function and then call response with it.
        $newresponse = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        debugger("newresponts: {$newresponse}", 3);
        return respond($newresponse);
    } elseif (strtoupper($xmlnode["tag"]) == "SR") {
        return respond($inputstar[0]);
    } elseif (strtoupper($xmlnode["tag"]) == "RANDOM") {
        $liarray = array();
        $children = $xmlnode["children"];
        for ($randomc = 0; $randomc < sizeof($children); $randomc++) {
            if (strtoupper($children[$randomc]["tag"]) == "LI") {
                $liarray[] = $randomc;
            }
        }
        // Pick a random number from 0 to sizeof($liarray)-1
        mt_srand((double) microtime() * 1000000);
        $lirandom = mt_rand(0, sizeof($liarray) - 1);
        return recursechildren(realchild($children[$liarray[$lirandom]]), $inputstar, $thatstar, $topicstar);
    } elseif (strtoupper($xmlnode["tag"]) == "THINK") {
        recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        return "";
    } elseif (strtoupper($xmlnode["tag"]) == "BOT") {
        $mynode = upperkeysarray($xmlnode["attributes"]);
        //$name=$xmlnode["attributes"]["NAME"];
        $name = $mynode["NAME"];
        return botget($name);
    } elseif (strtoupper($xmlnode["tag"]) == "GET") {
        $mynode = upperkeysarray($xmlnode["attributes"]);
        //$name=$xmlnode["attributes"]["NAME"];
        $name = $mynode["NAME"];
        return bget($name);
    } elseif (strtoupper($xmlnode["tag"]) == "SET") {
        //$name=$xmlnode["attributes"]["NAME"];
        $mynode = upperkeysarray($xmlnode["attributes"]);
        $name = $mynode["NAME"];
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        bset($name, $value);
        return $value;
    } elseif (strtoupper($xmlnode["tag"]) == "UPPERCASE") {
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        return strtoupper($value);
    } elseif (strtoupper($xmlnode["tag"]) == "FORMAL") {
        $nvalue = "";
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        $value = strtolower($value);
        $words = split(" ", $value);
        for ($x = 0; $x < sizeof($words); $x++) {
            if ($x != 0) {
                $nvalue .= " ";
            }
            $nvalue .= ucfirst($words[$x]);
        }
        return $nvalue;
    } elseif (strtoupper($xmlnode["tag"]) == "LOWERCASE") {
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        return strtolower($value);
    } elseif (strtoupper($xmlnode["tag"]) == "GENDER") {
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        return gender($value);
    } elseif (strtoupper($xmlnode["tag"]) == "SENTENCE") {
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        return ucfirst($value);
    } elseif (strtoupper($xmlnode["tag"]) == "INPUT") {
        $mynode = upperkeysarray($xmlnode["attributes"]);
        //$index = $xmlnode["attributes"]["INDEX"];
        if (!(is_array($mynode) && isset($mynode["INDEX"]))) {
            $mynode["INDEX"] = "";
        }
        $index = $mynode["INDEX"];
        if ($index == "") {
            $index = 1;
        }
        $index = $index - 1;
        return getinput($index);
    } elseif (strtoupper($xmlnode["tag"]) == "GOSSIP") {
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        insertgossip($value);
        return $value;
    } elseif (strtoupper($xmlnode["tag"]) == "PERSON") {
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        if ($value == "") {
            $value = $inputstar[0];
        }
        return firstthird($value);
    } elseif (strtoupper($xmlnode["tag"]) == "PERSON2") {
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        if ($value == "") {
            $value = $inputstar[0];
        }
        return firstsecond($value);
    } elseif (strtoupper($xmlnode["tag"]) == "THAT") {
        $mynode = upperkeysarray($xmlnode["attributes"]);
        //$indexes = $xmlnode["attributes"]["INDEX"];
        if (is_array($mynode) && isset($mynode["INDEX"])) {
            $indexes = $mynode["INDEX"];
        } else {
            $indexes = "";
        }
        $indexes = split(",", $indexes);
        if (sizeof($indexes) < 2) {
            $indexes = array();
            $indexes[] = 1;
            $indexes[] = 1;
        }
        return getthat($indexes[0], $indexes[1]);
    } elseif (strtoupper($xmlnode["tag"]) == "CONDITION") {
        $mynode = upperkeysarray($xmlnode["attributes"]);
        // First do multi condition name=value
        if (is_array($mynode) && isset($mynode["NAME"])) {
            $condname = $mynode["NAME"];
        } else {
            $condname = "";
        }
        if (is_array($mynode) && isset($mynode["VALUE"])) {
            $condvalue = $mynode["VALUE"];
        } else {
            $condvalue = "";
        }
        if (is_array($mynode) && isset($mynode["CONTAINS"])) {
            $condcontains = $mynode["CONTAINS"];
        } else {
            $condcontains = "";
        }
        if (is_array($mynode) && isset($mynode["EXISTS"])) {
            $condexists = $mynode["EXISTS"];
        } else {
            $condexists = "";
        }
        /*
        		$condname=$mynode["NAME"];
        		$condvalue=$mynode["VALUE"];
        		$condcontains=$mynode["CONTAINS"];
        		$condexists=$mynode["EXISTS"];
        */
        // If this is a multi condition
        if ($condname != "" && $condvalue != "") {
            if ($condvalue != "") {
                $condtype = "VALUE";
            } elseif ($condcontains != "") {
                $condtype = "CONTAINS";
            } elseif ($condexists != "") {
                $condtype = "EXISTS";
            }
            if ($condtype == "VALUE") {
                $condvalue = "^" . str_replace("*", "(.*)", $condvalue);
                //if ((bget($condname))==$condvalue){
                #				if (eregi($condvalue,bget($condname))){
                if (stripos(bget($condname), $condvalue) !== false) {
                    return recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
                }
            }
        } elseif ($condname != "" && $condvalue == "") {
            $children = $xmlnode["children"];
            $checkval = bget($condname);
            // After a match break. If no match then execute last if no name or val
            for ($randomc = 0; $randomc < sizeof($children); $randomc++) {
                if (strtoupper($children[$randomc]["tag"]) == "LI") {
                    $mynode = upperkeysarray($children[$randomc]["attributes"]);
                    //$condvalue=$children[$randomc]["attributes"]["VALUE"];
                    if (!(is_array($mynode) && isset($mynode["VALUE"]))) {
                        $mynode["VALUE"] = "";
                    }
                    $condvalue = $mynode["VALUE"];
                    $condvalue = "^" . str_replace("*", "(.*)", $condvalue) . "\$";
                    #					if ((eregi($condvalue,$checkval))||($condvalue=="^\$")){
                    if (preg_match("/" . $condvalue . "/i", $checkval) || $condvalue == "^\$") {
                        return recursechildren(realchild($children[$randomc]), $inputstar, $thatstar, $topicstar);
                    }
                }
            }
        } elseif ($condname == "" && $condvalue == "") {
            $children = $xmlnode["children"];
            // After a match break. If no match then execute last if no name or val
            for ($randomc = 0; $randomc < sizeof($children); $randomc++) {
                if (strtoupper($children[$randomc]["tag"]) == "LI") {
                    $mynode = upperkeysarray($children[$randomc]["attributes"]);
                    if (is_array($mynode) && isset($mynode["NAME"])) {
                        $condname = $mynode["NAME"];
                    } else {
                        $condname = "";
                    }
                    if (is_array($mynode) && isset($mynode["VALUE"])) {
                        $condvalue = $mynode["VALUE"];
                    } else {
                        $condvalue = "";
                    }
                    $condvalue = "^" . str_replace("*", "(.*)", $condvalue) . "\$";
                    #					if ((eregi($condvalue,bget($condname))) || (($condvalue=="^\$")&&($condname==""))){
                    if (preg_match("/" . $condvalue . "/i", bget($condname)) || $condvalue == "^\$" && $condname == "") {
                        return recursechildren(realchild($children[$randomc]), $inputstar, $thatstar, $topicstar);
                    }
                }
            }
        }
    } elseif (strtoupper($xmlnode["tag"]) == "SYSTEM") {
        $command = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        exec($command, $execoutput);
        for ($x = 0; $x < sizeof($execoutput); $x++) {
            $allout = $allout . $execoutput[$x];
        }
        return $allout;
    } elseif (strtoupper($xmlnode["tag"]) == "PHP") {
        $phpcode = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        ob_start();
        eval($phpcode);
        $evaled = ob_get_contents();
        ob_end_clean();
        return $evaled;
    } elseif (strtoupper($xmlnode["tag"]) == "JUSTBEFORETHAT") {
        $indexes = array();
        $indexes[] = 2;
        $indexes[] = 1;
        return getthat($indexes[0], $indexes[1]);
    } elseif (strtoupper($xmlnode["tag"]) == "JUSTTHAT") {
        $index = 2;
        $index = $index - 1;
        return getinput($index);
    } elseif (strtoupper($xmlnode["tag"]) == "BEFORETHAT") {
        $index = 3;
        $index = $index - 1;
        return getinput($index);
    } elseif (strtoupper($xmlnode["tag"]) == "GET_IP") {
        return getid();
    } elseif (strtoupper($xmlnode["tag"]) == "GETNAME") {
        $name = "NAME";
        return bget($name);
    } elseif (strtoupper($xmlnode["tag"]) == "GETSIZE") {
        return getsize();
    } elseif (strtoupper($xmlnode["tag"]) == "GETTOPIC") {
        $name = "TOPIC";
        return bget($name);
    } elseif (strtoupper($xmlnode["tag"]) == "GETVERSION") {
        return PROGRAMEVERSION;
    } elseif (substr(strtoupper($xmlnode["tag"]), 0, 4) == "GET_") {
        $name = substr($xmlnode["tag"], 4);
        return bget($name);
    } elseif (strtoupper($xmlnode["tag"]) == "SETNAME") {
        $name = "NAME";
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        bset($name, $value);
        return $value;
    } elseif (strtoupper($xmlnode["tag"]) == "SETTOPIC") {
        $name = "TOPIC";
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        bset($name, $value);
        return $value;
    } elseif (substr(strtoupper($xmlnode["tag"]), 0, 4) == "SET_") {
        $name = substr($xmlnode["tag"], 4);
        $value = recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar);
        bset($name, $value);
        return $value;
    } elseif (isdeprecated(strtoupper($xmlnode["tag"]), $ttag)) {
        $name = $ttag;
        return botget($name);
    } elseif (iscustomtag(strtoupper($xmlnode["tag"]), $ctfunction)) {
        return $ctfunction($xmlnode, $inputstar, $thatstar, $topicstar);
    } else {
        $name = $xmlnode["tag"];
        $atts = $xmlnode["attributes"];
        $atttext = "";
        if ($atts != NULL) {
            foreach ($atts as $key => $value) {
                $atttext .= " {$key}=\"{$value}\"";
            }
        }
        $value = "<{$name}" . $atttext;
        if (isset($xmlnode["children"]) || strcmp($xmlnode["value"], "") != 0) {
            $value .= ">" . recursechildren(realchild($xmlnode), $inputstar, $thatstar, $topicstar) . "</{$name}>";
        } else {
            $value .= "/>";
        }
        return $value;
    }
}
コード例 #2
0
ファイル: customtags.php プロジェクト: aparaschivoiu/webapp
function ct_if($xmlnode, $inputstar, $thatstar, $topicstar)
{
    $ch = array();
    $s = false;
    $condition = false;
    if (isset($xmlnode['attributes']['value'])) {
        $condition = bget($xmlnode['attributes']['name']) == $xmlnode['attributes']['value'];
    } elseif (isset($xmlnode['attributes']['contains'])) {
        $condition = preg_match('/' . $xmlnode['attributes']['contains'] . '/i', bget($xmlnode['attributes']['name'])) == 1 ? true : false;
    } elseif (isset($xmlnode['attributes']['exists'])) {
        $precondition = bget($xmlnode['attributes']['name']) == DEFAULTPREDICATEVALUE;
        $condition = $precondition != (bool) $xmlnode['attributes']['exists'];
    }
    if ($condition) {
        //If condition is satisfied, so we process every child before the 'else' tag (if there is any)
        foreach ($xmlnode["children"] as $i => $c) {
            if (isset($c['tag']) && $c['tag'] == 'else') {
                break;
            } else {
                $ch[] = $c;
            }
        }
        return recursechildren($ch, $inputstar, $thatstar, $topicstar);
    } else {
        //The If condition is not satisfied so be search for anything after an 'else' tag and we process
        foreach ($xmlnode["children"] as $i => $c) {
            if (isset($c['tag']) && $c['tag'] == 'else') {
                $s = true;
            } elseif ($s) {
                $ch[] = $c;
            }
        }
        return recursechildren($ch, $inputstar, $thatstar, $topicstar);
    }
}
コード例 #3
0
            }
        }
        #		$DbLink->clean_results();
    }
    $D1 = trim($D1);
    $DR = addslashes($D1);
    $DbLink->query("INSERT INTO " . C_MSG_TBL . " VALUES ('{$T}', '{$R}', '{$BOT}', '0', '{$mytime}', '{$U}', '{$DR}', '{$Readu}', '{$UR}')");
}
// End of function
#$DbLink->close();
// set and execute the above function via an if statment WORKS
#  if (eregi(mb_convert_case(C_BOT_NAME,MB_CASE_LOWER,$Charset), mb_convert_case($M,MB_CASE_LOWER,$Charset)) || eregi(mb_convert_case(C_BOT_NAME,MB_CASE_LOWER,$Charset), mb_convert_case($Private,MB_CASE_LOWER,$Charset)))
if (stripos(mb_convert_case($M, MB_CASE_LOWER, $Charset), mb_convert_case(C_BOT_NAME, MB_CASE_LOWER, $Charset)) !== false || stripos(mb_convert_case($Private, MB_CASE_LOWER, $Charset), mb_convert_case(C_BOT_NAME, MB_CASE_LOWER, $Charset)) !== false) {
    global $M, $botmess, $Charset;
    $botmess = str_replace(C_BOT_NAME, "", $M);
    //    $botmess = str_replace(mb_convert_case(C_BOT_NAME,MB_CASE_LOWER,$Charset), " ", mb_convert_case($M,MB_CASE_LOWER,$Charset));
    if ($R == $UR) {
        $UR = "";
    }
    bottalk_priv($botmess, $R, $UR, $Private, $Read);
    if (bget("name") == "") {
        bset("name", $U);
    }
}
#     if (eregi(mb_convert_case("bye ".C_BOT_NAME,MB_CASE_LOWER,$Charset), mb_convert_case($M,MB_CASE_LOWER,$Charset)) || eregi(mb_convert_case(C_BOT_NAME."> bye",MB_CASE_LOWER,$Charset), mb_convert_case($M,MB_CASE_LOWER,$Charset)) || eregi(mb_convert_case(C_BOT_NAME."> bye</FONT>",MB_CASE_LOWER,$Charset), mb_convert_case($M,MB_CASE_LOWER,$Charset)))
if (stripos(mb_convert_case($M, MB_CASE_LOWER, $Charset), mb_convert_case("bye " . C_BOT_NAME, MB_CASE_LOWER, $Charset)) !== false || stripos(mb_convert_case($M, MB_CASE_LOWER, $Charset), mb_convert_case(C_BOT_NAME . "> bye", MB_CASE_LOWER, $Charset)) !== false || stripos(mb_convert_case($M, MB_CASE_LOWER, $Charset), mb_convert_case(C_BOT_NAME . "> bye</FONT>", MB_CASE_LOWER, $Charset)) !== false) {
    if (file_exists($botpath)) {
        unlink($botpath);
    }
    // it deletes the users file if found (Stops coversation with bot)
}