Example #1
0
/**
 * Shows query window configuration form
 *
 * @param   array   optional defaults
 *
 * @return  nothing
 */
function show_window_form($defaults = array())
{
    ?>
<form method="post" action="">
    <?php 
    echo get_hidden_inputs();
    ?>
    <input type="hidden" name="action" value="lay_window_real" />
    <?php 
    show_config_form(array(array('Edit SQL in window', 'EditInWindow', 'Whether edit links will edit in query window.', TRUE), array('Query window height', 'QueryWindowHeight', 'Height of query window'), array('Query window width', 'QueryWindowWidth', 'Width of query window'), array('Default tab', 'QueryWindowDefTab', 'Default tab on query window', array('sql', 'files', 'history', 'full'))), 'Configure query window', 'Select desired query window look and feel.', $defaults);
    ?>
</form>
    <?php 
}
function _main()
{
    global $app_id, $app_secret, $uid, $recv_id, $access_token;
    echo "<h2>Facebook Chat Bot</h2>";
    if (isset($_GET['app_id'])) {
        $app_id = $_GET['app_id'];
    }
    if (isset($_GET['app_secret'])) {
        $app_secret = $_GET['app_secret'];
    }
    if (isset($_GET['uid'])) {
        $uid = $_GET['uid'];
    }
    if (isset($_GET['recv_id'])) {
        $recv_id = $_GET['recv_id'];
    }
    // if app_id or app_secret not set, show config form.
    if (empty($app_id) || empty($app_secret)) {
        show_config_form();
        exit;
    }
    // get access_token if not set
    if (!isset($access_token) || empty($access_token)) {
        echo '<p>Trying to getting access_token ... ';
        $access_token = get_access_token($app_id, $app_secret, current_url());
        if (empty($access_token)) {
            unset($_GET['code']);
            echo "<script>top.location.href='" . current_url(true) . '?' . http_build_query($_GET) . "'</script>";
            exit;
        }
        echo 'Done.</p>';
        echo '<p>access_token: ' . $access_token . '</p>';
    }
    // get uid from Facebook /me
    if (empty($uid)) {
        $json_me = json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' . $access_token));
        $uid = $json_me->id;
        echo "<p>uid empty, get uid from Graph API. uid= " . $uid . "</p>";
    }
    // if reciver empty, receiver will be sender.
    if (empty($recv_id)) {
        $recv_id = $uid;
    }
    // $json_friends = json_decode(file_get_contents('https://graph.facebook.com/me/friends?access_token='.$access_token));
    // list_array($json_friends->data);
    _post();
}