<?php

/** EDIT THIS **/
$GLOBALS['nabazSerial']      = "";
$GLOBALS['nabazToken']       = "";
$GLOBALS['nabazScriptPath'] = "/webinc/nabaz.php";
/** DON'T EDIT BELLOW THIS LINE **/

echo nabazTTS();

function 
nabazTTS() {
    if ( ! empty(
$_POST['nabazMessage']) && empty($_POST['nabazWidgedSpamtrapField']) ) {
        
$url      'http://api.nabaztag.com/vl/FR/api.jsp?sn='.$GLOBALS['nabazSerial'].'&token='.$GLOBALS['nabazToken'].'&ttlive=300&tts=';
        
$url     .= urlencode($_POST['nabazMessage']);
        
        
$ch       curl_init($url);
        
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
$response curl_exec($ch);
        
$status   curl_getinfo($chCURLINFO_HTTP_CODE);
        
curl_close($ch);
        if (
$status == 200) {
            
$response strpos($response'<message>TTSSEND</message><comment>Your text has been sent</comment>'); //They don't send valid XML, please don't fire me if you read this, chregu :)
            
if ($response !== false) {
                return 
'Message sent :)';
            }
        }
        
        return 
'Failed while sending message...';
    } else {
        
?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
                "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
            <head>
                <title>Nabaz Widget Test</title>
                <style type="text/css">
                    #nabazWidget {
                        font-size:10px;
                    }

                    #nabazWidgedSpamtrap {
                        display: none;
                    }
                    #nabazWidget input {
                        border:1px dotted #666666;
                    }
                </style>
                <script src="http://yui.yahooapis.com/2.2.0/build/yahoo/yahoo-min.js"></script>
                <script src="http://yui.yahooapis.com/2.2.0/build/event/event-min.js"></script>
                <script src="http://yui.yahooapis.com/2.2.0/build/connection/connection-min.js"></script>
            </head>
            <body>
            <div id="nabazWidget">
                <h3 class="blog">My Nabaztag</h3>
                <form action="<?php echo $GLOBALS['nabazScriptPath']; ?>" method="post" onsubmit="return false;">
                    <div id="nabazWidgetContent">
                        <label for="nabazMessage">Let him speak something:</label><br />
                        <input type="text" id="nabazMessage" name="nabazMessage"/>
                        <div id="nabazWidgedSpamtrap">
                            <label for="nabazWidgedSpamtrapField">This is only for Spammers. DONT USE!</label>
                            <input type="text" id="nabazWidgedSpamtrapField" name="nabazWidgedSpamtrapField"/>
                        </div>
                    </div>
                </form>
                <script type="text/javascript">
                    /** EDIT THIS **/
                    var url = '<?php echo $GLOBALS['nabazScriptPath']; ?>';
                    /** DON'T EDIT BELLOW THIS LINE **/
                    var msgFld = document.getElementById('nabazMessage');
                    function nabazWidgetStatus(a) {
                        document.getElementById('nabazWidgetContent').innerHTML = a.responseText;
                    }
                    function nabazWidgetKeyCallback(e) {
                        if (e.keyCode == 13) { //Pressed Enter
                            document.getElementById('nabazWidgetContent').innerHTML = 'Sending message...';
                            YAHOO.util.Connect.asyncRequest('POST', url, {success: function(a) {nabazWidgetStatus(a)}}, 'nabazMessage='+msgFld.value); 
                        }
                    }
                    YAHOO.util.Event.addListener(msgFld, 'keypress', nabazWidgetKeyCallback);
                </script>
            </div>

            </body>
            </html>
        <?php
    
}
}