wordpress插件facebook autopost不工作

时间:2014-04-24 10:58:03

标签: php facebook wordpress wordpress-plugin

我正在编写一个wordpress插件,让用户在分享他的电子邮件信息后让我自动进行下载(1个广告)。

一切正常,除非我到达autopost部分,当用户点击接受时我得到500内部错误。

我尝试过改变一些事情,但仍然是一样的。我认为错误来自代码的这一部分,但无法看到它。有什么建议吗?

<?php

class Fb_wpress_locker_logic {

function Fb_wpress_locker_logic() {

    if(session_id()=='') session_start();
    require_once(ABSPATH . WPINC . '/pluggable.php');

    /*
    if(count($_GET)>0) {
        echo $_GET['fb_locker'];
        exit();
    }
    */

    //Unlock a content
    if(@$_GET['fb_locker']=='unlock' && is_numeric(@$_GET['id'])) {

        if(@$_GET['redirect']!='') {
            $_SESSION['tmp']['redirect'] = @$_GET['redirect'];
            $_SESSION['tmp']['get'] = @$_GET;
        }

        //get parameters
        $id = @$_GET['id'];

        $scope = 'publish_stream,email'; //scope
        if (!class_exists('Fb_ypbox')) include_once('include/library/Fb_box/include/webzone.php');
        $f1 = new Fb_ypbox(array('fb_app_id'=>$GLOBALS['ygp_fb_wpress_locker']['fb_app_id'], 'fb_app_secret'=>$GLOBALS['ygp_fb_wpress_locker']['fb_app_secret'], 'fb_scope'=>$scope));
        $connect_result = $f1->fb_connect_flow(array('current_url'=>$_SESSION['tmp']['redirect'].'?fb_locker=unlock&id='.@$_GET['id']));

        //Connected successfully
        if($connect_result && !is_multisite()) {

            //params
            $autopost = @$_SESSION['tmp']['get']['autopost']; //autopost
            $message = @$_SESSION['tmp']['get']['message'];
            $picture = @$_SESSION['tmp']['get']['picture'];

            $userData = $f1->getUserData();
            $current_page = $_SESSION['tmp']['redirect'];

            $db1 = new Fb_wpress_locker_db();
            $result = $db1->selectFbUsers(array('fb_id'=>$userData['id']));

            //Update locked content
            if(count($result)>0) {
                $unlocked_ids_db = $result[0]['unlocked_ids'];
                $unlocked_ids = json_decode($unlocked_ids_db, true);
                if($unlocked_ids=='') $unlocked_ids=array();
                if(!in_array($id, $unlocked_ids)) {
                    $unlocked_ids[] = $id;

                    //autopost
                    self::autopost_on_user_wall(array('fb_id'=>$userData['id'], 'autopost'=>$autopost, 'message'=>$message, 'picture'=>$picture, 'link'=>$current_page));
                }
                $unlocked_ids = json_encode($unlocked_ids);

                $db1 = new Fb_wpress_locker_db();
                $db1->updateFbUser(array('unlocked_ids'=>$unlocked_ids, 'fb_token'=>$userData['token'], 'fb_token_expires'=>$userData['token_expires']), array('fb_id'=>$userData['id']));
            }
            //Add user and locked content id
            else {
                $unlocked_ids[] = $id;
                $unlocked_ids = json_encode($unlocked_ids);
                $db1 = new Fb_wpress_locker_db();
                $db1->insertFbUser(array('fb_id'=>$userData['id'], 'fb_name'=>$userData['name'], 'fb_email'=>$userData['email'], 'fb_token'=>$userData['token'], 'fb_token_expires'=>$userData['token_expires'], 'unlocked_ids'=>$unlocked_ids, 'created'=>date('Y-m-d H:i:s')));                   
                //autopost
                self::autopost_on_user_wall(array('fb_id'=>$userData['id'], 'autopost'=>$autopost, 'message'=>$message, 'picture'=>$picture, 'link'=>$current_page));
            }
        }

        echo '<script>window.location = "'.$_SESSION['tmp']['redirect'].'";</script>';
    }

    else if(@$_GET['fb_locker']=='lock' && is_numeric(@$_GET['id'])) {

        if (!class_exists('Fb_ypbox')) include_once('include/library/Fb_box/include/webzone.php');
        $f1 = new Fb_ypbox(array('fb_app_id'=>$GLOBALS['ygp_fb_wpress_locker']['fb_app_id'], 'fb_app_secret'=>$GLOBALS['ygp_fb_wpress_locker']['fb_app_secret'], 'fb_scope'=>$scope));
        $userData = $f1->getUserData();
        $id = @$_GET['id'];

        //User connected to Facebook
        if(count($userData)>0) {

            $db1 = new Fb_wpress_locker_db();
            $result = $db1->selectFbUsers(array('fb_id'=>$userData['id']));

            if(count($result)>0) {
                $unlocked_ids_db = $result[0]['unlocked_ids'];
                $unlocked_ids = json_decode($unlocked_ids_db, true);
                if($unlocked_ids=='') $unlocked_ids=array();

                $unlocked_ids2 = array();
                for($i=0; $i<count($unlocked_ids); $i++) {
                    if($unlocked_ids[$i]!=$id) $unlocked_ids2[] = $unlocked_ids[$i];
                }
                $unlocked_ids2 = json_encode($unlocked_ids2);

                //print_r($unlocked_ids);
                $db1 = new Fb_wpress_locker_db();
                $db1->updateFbUser(array('unlocked_ids'=>$unlocked_ids2), array('fb_id'=>$userData['id']));
            }
        }

        //Redirect
        echo '<script>window.location = "'.$_SESSION['tmp']['redirect'].'";</script>';
    }
}

//Update user wall
function autopost_on_user_wall($criteria=array()) {
    $fb_id = $criteria['fb_id'];
    $autopost = $criteria['autopost'];
    $message = $criteria['message'];
    $link = $criteria['link'];
    $picture = $criteria['picture'];

    if($autopost=='') $autopost = $GLOBALS['ygp_fb_wpress_locker']['autopost'];
    if($message=='') $message = $GLOBALS['ygp_fb_wpress_locker']['autopost_message'];
    if($picture=='') $picture = $GLOBALS['ygp_fb_wpress_locker']['autopost_picture'];

    $pos = strpos($link, 'localhost');
    if($pos>0) $link='';

    if($message!='' && $autopost==1) {
        if (!class_exists('Fb_ypbox')) include_once('include/library/Fb_box/include/webzone.php');
        $f1 = new Fb_ypbox(array('fb_app_id'=>$GLOBALS['ygp_fb_wpress_locker']['fb_app_id'], 'fb_app_secret'=>$GLOBALS['ygp_fb_wpress_locker']['fb_app_secret']));
        $userData = $f1->getUserData();
        $result = $f1->updateFacebookStatus(array('fb_id'=>$fb_id, 'message'=>$message, 'link'=>$link, 'picture'=>$picture));
        $result = json_decode($result, true);
        if($result['error']['message']!='') {
            echo '<script>alert("Autopost failed: '.$result['error']['message'].'");</script>';
        }
    }       
}
}

  new Fb_wpress_locker_logic();

 ?>

0 个答案:

没有答案