Ejemplo n.º 1
0
function handleFacebookMessage($message, $uid, $db, $user_object, $total, $type)
{
    switch ($type) {
        case "fb":
            $con = "AND (expires_at>" . time() . " OR expires_at=0)";
            break;
        case "fbp":
            $con = "";
            break;
    }
    $condition = "SELECT *  FROM manager_" . $type . "_acc  WHERE userid=" . $uid . " AND expired=0  {$con}";
    if ($fbacc = $db->query($condition)) {
        if ($fbacc->rowCount() > 0) {
            $fbacc = $fbacc->fetch();
            /*foreach($fbacc as $key=>$value)
            		error_log(" $key => $value ");*/
            $timezone = time() + $fbacc['timezone'];
            $lastTime = $user_object->getLastPublishedTime($uid, $type, 1);
            $limit = $user_object->getAllPublishedWithinTimeFrame($uid, $type, 30, $timezone);
            if ($limit < 45 && sanityCheck($timezone, $lastTime, $total)) {
                try {
                    $hfb = new Handler_Facebook();
                    error_log(json_encode($message->getFacebookPostBody()));
                    if ($post = $hfb->post("/me/feed", $message->getFacebookPostBody(), $fbacc['access_token'])) {
                        $table = "manager_stats";
                        $fields = array("userid" => $uid, "social_network" => $type, "user_id" => $fbacc['user_id'], "message" => $message->getStatus(), "message_id" => $post['id'], "type" => 1, "time" => $timezone);
                        $db->doInsert($table, $fields);
                        $message->setLastShare();
                    } else {
                        error_log($hfb->getErrorMes());
                    }
                } catch (Exception $e) {
                    error_log($e);
                }
            }
        }
    }
}
Ejemplo n.º 2
0
function handleFacebookMessage($message, $db, $user_object, $type)
{
    $uid = $message->getPubId();
    switch ($type) {
        case "fb":
            $con = "AND (expires_at>" . time() . " OR expires_at=0)";
            break;
        case "fbp":
            $con = "";
            break;
    }
    $condition = "SELECT *  FROM manager_" . $type . "_acc  WHERE userid=" . $uid . " AND expired=0  {$con}";
    if ($fbacc = $db->query($condition)) {
        if ($fbacc->rowCount() > 0) {
            $fbacc = $fbacc->fetch();
            $timezone = time() + $fbacc['timezone'];
            $limit = $user_object->getAllPublishedWithinTimeFrame($uid, $type, 30, $timezone);
            if ($limit < 45) {
                try {
                    $hfb = new Handler_Facebook();
                    if ($post = $hfb->post($message->getFacebookTarget(), $message->getFacebookPostBody(), $fbacc['access_token'])) {
                        $table = "manager_stats";
                        $fields = array("userid" => $uid, "social_network" => $type, "user_id" => $fbacc['user_id'], "message" => $message->getStatus(), "message_id" => $post['id'], "type" => 1, "time" => $timezone);
                        $db->doInsert($table, $fields);
                    } else {
                        error_log($hfb->getErrorMes());
                    }
                } catch (Exception $e) {
                    error_log($e);
                }
            }
        }
    }
}