View file chatbot\index.php

File size: 4.59Kb
<?php
ini_set("display_errors",0);
header("Content-type: text/vnd.wap.wml");
header("Cache-Control: no-store, no-cache, must-revalidate");
print "<?xml version=\"1.0\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"". " \"http://www.wapforum.org/DTD/wml_1.1.xml\">";
?>
<wml>
<?php
$botname = isset($_REQUEST['botname']) ? $_REQUEST['botname'] : "J21Princess";
$botid = isset($_REQUEST['botid']) ? $_REQUEST['botid'] : "8320b2391e36e4f6";
$lb = isset($_REQUEST['lb']) ? $_REQUEST['lb'] : $_SERVER['HTTP_REFERER'];
$input = isset($_POST["input"]) ? $_POST["input"] : '';
$custid=isset($_POST["custid"]) ? $_POST["custid"] : '' ;
$hostname = "www.pandorabots.com";
$hostpath = "/pandora/talk-xml";
 echo "<card id=\"main\" title=\"$botname\">";                   //start of main card
        echo "<p align=\"center\">";
        echo "<br/>";
		include("ads.php");
		echo "<br/>";
    if ($input!="")
    {
        $sendData = "botid=".$botid."&input=".urlencode($input)."&custid=".$custid;
    	// Send the request to Pandorabot
    	$result = PostToHost($hostname, $hostpath, $sendData);
    	//TODO: Process the returned XML as an XML document instead of a big string.
    	// Use string manipulations to pull out the 'custid' and 'that' values.
    	$pos = strpos($result, "custid=\"");

    	// Extract the custid
    	if ($pos === false) {
    		$custid = "";
    	} else {
    		$pos += 8;
    		$endpos = strpos($result, "\"", $pos);
    		$custid = substr($result, $pos, $endpos - $pos);
    	}
    	// Extrat <that> - this is the reply from the Pandorabot
    	$pos = strpos($result, "<that>");
    	if ($pos === false) {
    		$reply = "";
    	} else {
    		$pos += 6;
    		$endpos = strpos($result, "</that>", $pos);
    		$reply = unhtmlspecialchars(substr($result, $pos, $endpos - $pos));
    	}

        //echo htmlspecialchars( $reply);
        $hers = $reply;

             $input=htmlspecialchars($input);
             $nick = "YOU";
             echo "<br/><b>$nick: </b>$input<br/>";
             echo "<b>$botname: </b>$hers<br/>";
        echo "<br/><input type=\"text\" name=\"input\" maxlength=\"120\" value=\"$input\"/><anchor>";
        	echo " Send";
		echo "<go href=\"index.php\" method=\"post\">";
		echo "<postfield name=\"input\" value=\"$(input)\"/>";
		echo "<postfield name=\"custid\" value=\"$custid\"/>";
		echo "<postfield name=\"botid\" value=\"$botid\"/>";
		echo "<postfield name=\"lb\" value=\"$lb\"/>";
		echo "<postfield name=\"botname\" value=\"$botname\"/>";
						
		echo "</go>";
		echo "</anchor><br/>";
    }else{
      echo "We are happy to introduce <b>$botname</b><br/>Happy Chatting !<br/><br/> ";
      echo "<input type=\"text\" name=\"input\" maxlength=\"120\" value=\"$input\"/><anchor>";
		echo " Send";
		echo "<go href=\"index.php\" method=\"post\">";
		echo "<postfield name=\"input\" value=\"$(input)\"/>";
		echo "<postfield name=\"custid\" value=\"$custid\"/>";
		echo "<postfield name=\"botid\" value=\"$botid\"/>";
		echo "<postfield name=\"lb\" value=\"$lb\"/>";
		echo "<postfield name=\"botname\" value=\"$botname\"/>";
		echo "</go>";
		echo "</anchor><br/>";
    }
	echo "<br/><a href=\"$lb\">&#171; Back</a><br/>";
	echo "<br/>Powered by: <a href=\"http://masnun.com\">maSnun</a><br/>";

echo "</p>";
        echo "</card>";

function unhtmlspecialchars( $string )
{
  $string = str_replace ( '&amp;', '&', $string );
  $string = str_replace ( '&#039;', '\'', $string );
  $string = str_replace ( '&quot;', '"', $string );
  $string = str_replace ( '&lt;', '<', $string );
  $string = str_replace ( '&gt;', '>', $string );
  $string = str_replace ( '&uuml;', '?', $string );
  $string = str_replace ( '&Uuml;', '?', $string );
  $string = str_replace ( '&auml;', '?', $string );
  $string = str_replace ( '&Auml;', '?', $string );
  $string = str_replace ( '&ouml;', '?', $string );
  $string = str_replace ( '&Ouml;', '?', $string );
  return $string;
}

?>
<?php 
function PostToHost($host, $path, $data_to_send)
{

				$result = "";
        $fp = fsockopen($host,80,$errno, $errstr, 30);
        if( $fp)
        {
            fputs($fp, "POST $path HTTP/1.0\n");
        fputs($fp, "Host: $host\n");
        fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
        fputs($fp, "Content-length: " . strlen($data_to_send) . "\n");
        fputs($fp, "Connection: close\n\n");
        fputs($fp, $data_to_send);

        while(!feof($fp)) {
					$result .=  fgets($fp, 128);
        }
        fclose($fp);

        return $result;
        }


}

?>


</wml>