Beispiel #1
0
function execute($args)
{
    parse_str($args, $arr);
    $accessToken = $arr['access_token'];
    $accessTokenSecret = $arr['access_token_secret'];
    $fromHour = $arr['fromHour'];
    $toHour = $arr['toHour'];
    if (isset($arr['ack'])) {
        $ack = $arr['ack'];
    } else {
        $ack = 0;
    }
    if (isset($arr['order'])) {
        $order = $arr['order'];
    } else {
        $order = null;
    }
    if (isset($arr['lastTwtId'])) {
        $lastTwtId = (string) $arr['lastTwtId'];
    } else {
        $lastTwtId = null;
    }
    $returnValue = 0;
    $pattern = $arr['regexp'];
    $twtAccess = new ChiconTwitterGateway($accessToken, $accessTokenSecret);
    $return = $twtAccess->getMatchingPrivateMsg($pattern, $lastTwtId, $order);
    //var_dump($return);
    if (!empty($return) and !empty($return[0]["id"])) {
        //New matching tweet found at id
        $lastTwtId = $return[0]["id"];
        $order = "max_id";
        //preg_match('/(\d)$/', $lastTwtId, $match);
        //$d = $match[1]-1;
        //$lastTwtId = substr($lastTwtId, 0, -1).$d;
        if ($ack == 1) {
            //Needed because float to string conversion is hard to manage
            //preg_match('/(\d)$/', $lastTwtId, $match);
            //$d = $match[1]+1;
            //$lastTwtId = substr($lastTwtId, 0, -1).$d;
            $order = "since_id";
        } else {
            //Check if the give tweet is matching the hour
            $twHour = $return[0]["matches"][2];
            if (strtotime($twHour) > strtotime($fromHour) and strtotime($twHour) < strtotime($toHour) and $ack == 0) {
                $returnValue = 1000;
            }
        }
    }
    $new_args = "access_token=" . $accessToken . "&access_token_secret=" . $accessTokenSecret . "&fromHour=" . $fromHour . "&toHour=" . $toHour . "&regexp=" . $pattern;
    $new_args .= "&ack=0&lastTwtId=" . $lastTwtId . "&order=" . $order;
    global $SRV_INSTANCE;
    $SRV_INSTANCE->setConfigArgs($new_args);
    //echo $new_args;
    $myArray = array(0 => array("id" => 1, "value" => array($returnValue)));
    return $myArray;
}
function configure($args)
{
    if (isset($args['tweet'])) {
        while (!ChiconTwitterGateway::isAuthenticationCompleted()) {
        }
        $tweeterSession = ChiconTwitterGateway::getAccessToken();
        echo "<H3>Twitter auth completed with success<H3>";
        echo "<input type='hidden' name='access_token' value='" . $tweeterSession['oauth_token'] . "'>";
        echo "<input type='hidden' name='access_token_secret' value='" . $tweeterSession['oauth_token_secret'] . "'>";
        echo "<input type='hidden' name='auth' value='1'/>";
        echo "<H4>Please enter your matching regexp</H4>";
        echo "<input name='regexp' type='text'/>";
        echo "<H4>Please enter your matching schedule</H4>";
        echo " FROM <input name='fromHour' type='text'/> AM";
        echo " TO <input name='toHour' type='text'/> PM";
        return null;
    } elseif (isset($args['auth'])) {
        return "access_token=" . $args['access_token'] . "&access_token_secret=" . $args['access_token_secret'] . "&fromHour=" . $args['fromHour'] . "AM&toHour=" . $args['toHour'] . "PM&&regexp=" . $args['regexp'] . "&ack=0";
    } else {
        $t = ChiconTwitterGateway::getUserToken();
        echo "<input type='hidden' name='tweet' value='1'/>";
        return null;
    }
}
Beispiel #3
0
<?php

require "../addOn/ChiconTwitterGateway.class.php";
session_start();
$r = ChiconTwitterGateway::finishAuthentication();
echo "<HTML><BODY><SCRIPT>window.opener.document.getElementById('subCfg').click();window.close();</SCRIPT></BODY></HTML>";