Esempio n. 1
0
function buffer_send(&$a, &$b)
{
    if ($b['deleted'] || $b['private'] || $b['created'] !== $b['edited']) {
        return;
    }
    if (!strstr($b['postopts'], 'buffer')) {
        return;
    }
    if ($b['parent'] != $b['id']) {
        return;
    }
    // if post comes from buffer don't send it back
    //if($b['app'] == "Buffer")
    //	return;
    $client_id = get_config("buffer", "client_id");
    $client_secret = get_config("buffer", "client_secret");
    $access_token = get_pconfig($b['uid'], "buffer", "access_token");
    if ($access_token) {
        $buffer = new BufferApp($client_id, $client_secret, $callback_url, $access_token);
        require_once "include/plaintext.php";
        require_once "include/network.php";
        $profiles = $buffer->go('/profiles');
        if (is_array($profiles)) {
            logger("Will send these parameter " . print_r($b, true), LOGGER_DEBUG);
            foreach ($profiles as $profile) {
                if (!$profile->default) {
                    continue;
                }
                $send = false;
                switch ($profile->service) {
                    case 'appdotnet':
                        $send = $b["extid"] != NETWORK_APPNET;
                        $limit = 256;
                        $markup = false;
                        $includedlinks = true;
                        $htmlmode = 6;
                        break;
                    case 'facebook':
                        $send = $b["extid"] != NETWORK_FACEBOOK;
                        $limit = 0;
                        $markup = false;
                        $includedlinks = false;
                        $htmlmode = 9;
                        break;
                    case 'google':
                        $send = $b["extid"] != NETWORK_GPLUS;
                        $limit = 0;
                        $markup = true;
                        $includedlinks = false;
                        $htmlmode = 9;
                        break;
                    case 'twitter':
                        $send = $b["extid"] != NETWORK_TWITTER;
                        $limit = 140;
                        $markup = false;
                        $includedlinks = true;
                        $htmlmode = 8;
                        break;
                    case 'linkedin':
                        $send = $b["extid"] != NETWORK_LINKEDIN;
                        $limit = 700;
                        $markup = false;
                        $includedlinks = true;
                        $htmlmode = 2;
                        break;
                }
                if (!$send) {
                    continue;
                }
                $item = $b;
                // Markup for Google+
                if ($markup) {
                    if ($item["title"] != "") {
                        $item["title"] = "*" . $item["title"] . "*";
                    }
                    $item["body"] = preg_replace("(\\[b\\](.*?)\\[\\/b\\])ism", '*$1*', $item["body"]);
                    $item["body"] = preg_replace("(\\[i\\](.*?)\\[\\/i\\])ism", '_$1_', $item["body"]);
                    $item["body"] = preg_replace("(\\[s\\](.*?)\\[\\/s\\])ism", '-$1-', $item["body"]);
                }
                $post = plaintext($a, $item, $limit, $includedlinks, $htmlmode);
                logger("buffer_send: converted message " . $b["id"] . " result: " . print_r($post, true), LOGGER_DEBUG);
                // The image proxy is used as a sanitizer. Buffer seems to be really picky about pictures
                require_once "mod/proxy.php";
                if (isset($post["image"])) {
                    $post["image"] = proxy_url($post["image"]);
                }
                if (isset($post["preview"])) {
                    $post["preview"] = proxy_url($post["preview"]);
                }
                //if ($profile->service == "twitter") {
                if ($includedlinks) {
                    if (isset($post["url"])) {
                        $post["url"] = short_link($post["url"]);
                    }
                    if (isset($post["image"])) {
                        $post["image"] = short_link($post["image"]);
                    }
                    if (isset($post["preview"])) {
                        $post["preview"] = short_link($post["preview"]);
                    }
                }
                // Seems like a bug to me
                // Buffer doesn't add links to Twitter and App.net (but pictures)
                //if ($includedlinks AND isset($post["url"]))
                if ($profile->service == "twitter" and isset($post["url"]) and $post["type"] != "photo") {
                    $post["text"] .= " " . $post["url"];
                } elseif ($profile->service == "appdotnet" and isset($post["url"]) and isset($post["title"]) and $post["type"] != "photo") {
                    $post["title"] = shortenmsg($post["title"], 90);
                    $post["text"] = shortenmsg($post["text"], $limit - (24 + strlen($post["title"])));
                    $post["text"] .= "\n[" . $post["title"] . "](" . $post["url"] . ")";
                } elseif ($profile->service == "appdotnet" and isset($post["url"]) and $post["type"] != "photo") {
                    $post["text"] .= " " . $post["url"];
                } elseif ($profile->service == "google") {
                    $post["text"] .= html_entity_decode(" ", ENT_QUOTES, 'UTF-8');
                }
                // Send a special blank to identify the post through the "fromgplus" addon
                $message = array();
                $message["text"] = $post["text"];
                $message["profile_ids[]"] = $profile->id;
                $message["shorten"] = false;
                $message["now"] = true;
                if (isset($post["title"])) {
                    $message["media[title]"] = $post["title"];
                }
                if (isset($post["description"])) {
                    $message["media[description]"] = $post["description"];
                }
                if (isset($post["url"]) and $post["type"] != "photo") {
                    $message["media[link]"] = $post["url"];
                }
                if (isset($post["image"])) {
                    $message["media[picture]"] = $post["image"];
                    if ($post["type"] == "photo") {
                        $message["media[thumbnail]"] = $post["image"];
                    }
                }
                if (isset($post["preview"])) {
                    $message["media[thumbnail]"] = $post["preview"];
                }
                //print_r($message);
                logger("buffer_send: data for message " . $b["id"] . ": " . print_r($message, true), LOGGER_DEBUG);
                $ret = $buffer->go('/updates/create', $message);
                logger("buffer_send: send message " . $b["id"] . " result: " . print_r($ret, true), LOGGER_DEBUG);
            }
        }
    }
}
Esempio n. 2
0
 public function postShareAd()
 {
     if (!Auth::check()) {
         return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'require_signin')), 500);
     }
     $data = post();
     $default = array('type' => '', 'page_id' => '', 'message' => '');
     $merge = array_merge($default, $data);
     $merge = \DLNLab\Classified\Classes\HelperClassified::trim_value($merge);
     extract($merge);
     require 'libraries/BufferApp/buffer.php';
     require 'libraries/SocialAutoPoster/SocialAutoPoster.php';
     $autoposter = new \SocialAutoPoster();
     try {
         switch ($type) {
             case 'facebook':
                 $facebook = $autoposter->getApi('facebook', array('page_id' => '408730579166315', 'appid' => '225132297553705', 'appsecret' => '8f00d29717ee8c6a49cd25da80c5aad8', 'access_token' => 'CAADMwbKfhykBAKj0OCExhhWBIRFJw5K1jRjijq3W4v7vkKgWHk3du1PfRXUtvKpVIcfJrFP32wuzFVpFW7DWlWhbZAz7sMyxhFcGUbJrMDR46tyiOcZAsvbKBoSEO7iymHuCzKgxfmtk0p3MuyRnZAKKCFapZBNGmRzF803pZBUVcZCLCghizLIgTO0mlH65Pk9WbtzXHKZC0uwwZAjMtkCq'));
                 $facebook->postToWall('Hello FB');
                 var_dump($facebook->getErrors());
                 break;
             case 'googleplus':
                 $client_id = '54c5d3d2a4a87d060fb822b5';
                 $client_secret = 'fa161986339e85b17d71f8d70b25efa9';
                 $callback_url = 'http://localhost/october/api/v1/callback_buffer';
                 $buffer = new \BufferApp($client_id, $client_secret, $callback_url);
                 $profiles = $buffer->go('/profiles');
                 if (is_array($profiles)) {
                     foreach ($profiles as $profile) {
                         $buffer->go('/updates/create', array('text' => 'My first status update from bufferapp-php worked!', 'profile_ids[]' => $profile->id));
                     }
                 }
                 //$gplus = AdSharePage::connect_gplus($autoposter);
                 //AdSharePage::post_gplus_wall($gplus, $page_id, $message);
                 break;
         }
     } catch (Exception $ex) {
         return Response::json(array('status' => $ex->getMessage()), 500);
     }
 }
Esempio n. 3
0
<?php

session_start();
require 'buffer.php';
$client_id = '';
$client_secret = '';
$callback_url = 'http://127.0.0.1/callback';
$buffer = new BufferApp($client_id, $client_secret, $callback_url);
if (!$buffer->ok) {
    echo '<a href="' . $buffer->get_login_url() . '">Connect to Buffer!</a>';
} else {
    $profiles = $buffer->go('/profiles');
    if (is_array($profiles)) {
        foreach ($profiles as $profile) {
            $buffer->go('/updates/create', array('text' => 'My first status update from bufferapp-php worked!', 'profile_ids[]' => $profile->id));
        }
    }
}