Esempio n. 1
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);
                }
            }
        }
    }
}
Esempio n. 2
0
function handleFacebookMessage($message, $uid, $db, $user_object, $total)
{
    $table = "manager_fb_acc";
    $condition = " userid=" . $uid . " AND expired=0 AND (expires_at>" . time() . " OR expires_at=0) ";
    if ($fbcc = $db->doSingleSelect($table, $condition)) {
        $timezone = time() + $fbacc['timezone'];
        $limit = $user_object->getAllPublishedWithinTimeFrame($uid, "fb", 30, $timezone);
        if ($limit < 45) {
            try {
                $hfb = new Handler_Facebook();
                if ($post = $hfb->post("/me/feed", $message->getFacebookPostBody(), $fbacc['access_token'])) {
                    $table = "manager_stats";
                    $fields = array("userid" => $uid, "social_network" => "fb", "user_id" => $fbacc['user_id'], "message" => $message->getStatus(), "message_id" => $post->{$response}['id'], "type" => 2, "time" => $timezone);
                    $db->doInsert($table, $fields);
                } else {
                    error_log($hfb->lastError);
                }
            } catch (Exception $e) {
                error_log($e);
            }
        }
    }
}
Esempio n. 3
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);
                }
            }
        }
    }
}
Esempio n. 4
0
<?php

require_once "../../clases/manager/autoload.php";
require_once "../../clases/bd.php";
use OneAManager\Handler_Facebook;
use OneAManager\Handler_NewSocialConnection;
$login = $_GET['state'] ? $_GET['state'] : 0;
try {
    $fbh = new Handler_Facebook();
    $hsc = new Handler_NewSocialConnection();
    $db = new bd();
    $permissions = ['user_posts', 'publish_actions', 'user_photos', 'manage_pages', 'publish_pages'];
    if ($info = $fbh->javascriptCallbackManager($permissions)) {
        $uid = $info['user_id'];
        $at = $info['access_token'];
        $table = "manager_fb_acc";
        $condition = " user_id=" . $uid;
        if ($result = $db->doSingleSelect($table, $condition)) {
            //account already belongs to a user
            if ($info["e"]) {
                //some error, could mean a lot of things, but whichever the case we need to expire all the accounts.
                $fbh->revokePermissions($at, array());
                $fields = array('expires_at' => 1, 'expired' => 1);
                $db->doUpdate($table, $fields, $condition);
                $return = array("e" => 2);
            } else {
                $ea = $info['expires_at'];
                $fields = array('access_token' => $at, 'expires_at' => $ea, 'expired' => 0);
                $db->doUpdate($table, $fields, $condition);
                switch ($login) {
                    case 0:
Esempio n. 5
0
<?php

require_once "../../clases/manager/autoload.php";
require_once "../../clases/bd.php";
use OneAManager\Handler_Facebook;
try {
    $fbh = new Handler_Facebook();
    $hsc = new Handler_NewSocialConnection();
    $db = new bd();
    if ($signed_request = $_REQUEST['signed_request']) {
        if ($data = $fbh->parseSignedRequest($signed_request)) {
            $uid = $data['user_id'];
            $table = "manager_fb_acc";
            if ($acc = $db->doSingleSelect($table, " user_id=" . $uid)) {
                $uuid = $acc['userid'];
                $table = "manager_fb_acc";
                $condition = " user_id=" . $uuid;
                $fields = array('expires_at' => 1, 'expired' => 1);
                $db->doUpdate($table, $fields, $condition);
                $table = "manager_fbp_acc";
                $fields = array('expired' => 1);
                $condition = " user_id=" . $uuid;
                $db->doUpdate($table, $fields, $condition);
                error_log("I've deleted {$uid}");
            } else {
                error_log("We got lucky, I guess! {$uid}");
            }
        }
    } else {
        error_log("No request");
    }