Пример #1
0
 /**
  * This is what happens, wenn the detection passes
  *
  * @param $lookup
  *
  * @return mixed
  */
 protected function handleDetectionComplete($lookup)
 {
     debugger()->info('Language detected: ' . $this->detected->slug);
     Cookie::queue($this->keys['cookie'], $this->detected->slug);
     $this->session->set($this->keys['session'], $this->detected->slug);
     $this->config->set('app.locale', $this->detected->slug);
     return $this->detected;
 }
Пример #2
0
 /**
  * Process the Detection
  *
  * @throws \Melon\Current\Exceptions\NotDetectableException
  * @return mixed|null
  */
 public function run($lookup = null)
 {
     $name = $this->getName();
     $key = $name . '_detection';
     debugger()->start($key, "[{$name}] Detection.");
     foreach ($this->getLookups($lookup) as $lookup) {
         $method = 'try' . $lookup;
         if (!method_exists($this, $method)) {
             continue;
         }
         if ($this->detected = $this->{$method}()) {
             debugger()->stop($key);
             fire(new CurrentEntityDetectedEvent($name, $this->detected, $lookup));
             return $this->handleDetectionComplete($lookup);
         }
     }
     debugger()->stop($key);
     throw new NotDetectableException($this->getName());
 }
Пример #3
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;
    }
}
Пример #4
0
 private function encode_respond($buffer)
 {
     debugger($buffer, 'Buffer Entity');
     $header = $body = '';
     $p = strpos($buffer, "\r\n\r\n");
     // 去除头部信息
     if ($p > 0) {
         $header = substr($buffer, 0, $p);
         if ($p + 4 < strlen($buffer)) {
             $body = substr($buffer, $p + 4);
         }
     }
     // 如果header为续传标记则继续去除头部信息
     if ($header = 'HTTP/1.1 100 Continue') {
         $p = strpos($body, "\r\n\r\n");
         if ($p > 0) {
             $header = substr($body, 0, $p);
             if ($p + 4 < strlen($body)) {
                 $body = substr($body, $p + 4);
             }
         }
     }
     /*
     $body_without_header = '';
     $p2 = strpos( $buffer, "<?xml" ); 	// 第一次出现XML标记的位置
     if( $p2 > 1 )
     {
     	if( $p2-1 < strlen($buffer) )
     	{
     		$body_without_header = substr( $buffer,$p2-1 );
     	}
     }
     */
     try {
         if ($this->_header['Accept-Encoding'] == 'gzip,deflate') {
             $body = @gzdecode($body);
             if (!$body) {
                 trigger_error('返回体解析错误', E_USER_WARNING);
             }
         }
         if ($this->_header['Transfer-Encoding'] == 'chunked') {
             $body = @http_chunked_decode($body);
         }
     } catch (Exception $e) {
         trigger_error($e);
     }
     return $body;
 }
Пример #5
0
function get_xml($url)
{
    $ch = curl_init();
    curl_setopt_array($ch, array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => ""));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("application/xml"));
    $xml = curl_exec($ch);
    $err = '';
    $errmsg = '';
    $header = '';
    $err = curl_errno($ch);
    $errmsg = curl_error($ch);
    $header = curl_getinfo($ch);
    unset($ch);
    debugger("err : {$err} errmsg : {$errmsg} header : " . print_r($header, TRUE));
    if ($xml != false) {
        $p = xml_parser_create();
        xml_parse_into_struct($p, $xml, $vals, $index);
        xml_parser_free($p);
        return $data;
    } else {
        return FALSE;
    }
}
Пример #6
0
function get_json($url)
{
    $ch = curl_init();
    curl_setopt_array($ch, array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => ""));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("application/json"));
    $json = curl_exec($ch);
    $err = '';
    $errmsg = '';
    $header = '';
    $err = curl_errno($ch);
    $errmsg = curl_error($ch);
    $header = curl_getinfo($ch);
    unset($ch);
    debugger("DEBUG : err : {$err} errmsg : {$errmsg} header : " . print_r($header, TRUE));
    if ($json != false) {
        $data = json_decode($json, TRUE);
        return $data;
    } else {
        return FALSE;
    }
}
Пример #7
0
/**
* Retrieve the template from the templates table
*
* Get the template from the templates table. and return it.
* 
* @todo The name {@link gettemplate()} and findtemplate() are too similar.
*
* @param integer $id                  The ID of the template to be returned
*
* @return string                      The contents of <template/> for this category.
*/
function findtemplate($id)
{
    $query = "select template from templates where id={$id}";
    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 "";
}
Пример #8
0
        }
        $count++;
    }
    ?>
        ]);

	var table = new google.visualization.Table(document.getElementById('table_div'));
        table.draw(data, {showRowNumber: true});
	}
  </script>
  </head>
  <body>

<?php 
    debugger("SQL : {$sql}");
    debugger("AND : {$AND}");
    print_r($_GET);
    ?>
    <div id="chart_div" style="width: 1000px; height: 600px;"></div>
    <div id="table_div" style="width: 1000px; height: 600px;"></div>
  </body>
</html>

<?php 
}
function debugger($msg)
{
    if (__DEBUG__) {
        echo "<p>DEBUG: {$msg}<p>";
    }
}
Пример #9
0
        $AND = " AND start_date between '" . $start_date . "' and '" . $end_date . "'";
    }
} else {
    $AND = "";
}
?>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
<?php 
//Get a list of games and API keys
$sql = "SELECT stat_date, sum(value) as value\n\t\tFROM star.s_game_day\n\t\tWHERE 1=1\n\t\t{$AND}\n\t\tAND stat_date between '2012-01-01' and '2012-08-17'\n\t\tAND metric='" . "ActiveUsersByDay' \n\t\tGROUP by 1\n\t\tORDER BY 1";
debugger("SQL : {$sql}");
$results =& $mdb2->query($sql);
$count = 1;
while ($row = $results->fetchRow(MDB2_FETCHMODE_ASSOC)) {
    if ($count > 1) {
        echo ",\n['" . $row['stat_date'] . "', " . $row['value'] . "]";
    } else {
        if ($count == 1) {
            echo "['Date', 'DAU'],\n";
            echo "['" . $row['stat_date'] . "', " . $row['value'] . "]";
        }
    }
    $count++;
}
?>
        ]);
Пример #10
0
function get_json($url)
{
    debugger("Memory Usage: get_json: " . memory_get_usage() . ".");
    $ch = curl_init();
    curl_setopt_array($ch, array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => ""));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("application/json"));
    $json = curl_exec($ch);
    $err = '';
    $errmsg = '';
    $header = '';
    $err = curl_errno($ch);
    $errmsg = curl_error($ch);
    $header = curl_getinfo($ch);
    curl_close($ch);
    if ($json != false) {
        return json_decode($json, TRUE);
    } else {
        $msg = "JSON return codes: err : {$err} errmsg : {$errmsg} header : ";
        if (!$header && $header != '') {
            $msg .= ": JSON header as follows:";
            note($msg);
            print_r($header, TRUE);
            echo "\n";
        }
        return FALSE;
    }
}