Exemplo n.º 1
0
 public function sendBufferUpdate($text = "", $now = true, $link = "", $picture = "", $thumbnail = "")
 {
     $settings = craft()->plugins->getPlugin('buffer')->getSettings();
     $bufferAccessToken = $settings['bufferAccessToken'];
     $bufferClientId = $settings['bufferClientId'];
     $bufferClientSecret = $settings['bufferClientSecret'];
     $bufferRedirectUri = $settings['bufferRedirectUri'];
     $twitterProfileId = $settings['twitterProfileId'];
     $facebookProfileId = $settings['facebookProfileId'];
     $googlePlusProfileId = $settings['googlePlusProfileId'];
     $pinterestProfileId = $settings['pinterestProfileId'];
     $linkedInPlusProfileId = $settings['linkedInProfileId'];
     if ($bufferAccessToken) {
         $buffer = new \BufferPHP($bufferAccessToken);
         if ($buffer) {
             $data = array('text' => $text, 'now' => $now, 'client_id' => $bufferClientId, 'client_secret' => $bufferClientSecret, 'redirect_uri' => $bufferRedirectUri, 'profile_ids' => array(), 'media' => array());
             if ($twitterProfileId) {
                 $data['profile_ids'][] = $twitterProfileId;
             }
             if ($facebookProfileId) {
                 $data['profile_ids'][] = $facebookProfileId;
             }
             if ($googlePlusProfileId) {
                 $data['profile_ids'][] = $googlePlusProfileId;
             }
             if ($pinterestProfileId) {
                 $data['profile_ids'][] = $pinterestProfileId;
             }
             if ($linkedInPlusProfileId) {
                 $data['profile_ids'][] = $linkedInPlusProfileId;
             }
             if ($link) {
                 $data['media']['link'] = $link;
             }
             if ($picture) {
                 $data['media']['picture'] = $picture;
                 $data['media']['photo'] = $picture;
             }
             if ($thumbnail) {
                 $data['media']['thumbnail'] = $thumbnail;
             }
             $ret = $buffer->post('updates/create', $data);
             BufferPlugin::log('sendBufferUpdate: ' . print_r($ret, 1));
         } else {
             BufferPlugin::log('new \\BufferPHP() failed');
         }
     }
 }
Exemplo n.º 2
0
// Taking care of the smart quotes
$article_title = preg_replace('/\\\\u([0-9a-z]{4})/', '&#x$1;', $article_title);
$article_excerpt = preg_replace('/\\\\u([0-9a-z]{4})/', '&#x$1;', $article_excerpt);
if (empty($article_url) || empty($article_title)) {
    exit("Need at least a title and a URL");
}
/* #2 Send link to Snip.ly */
// The data
$postData = array('url' => $article_url, 'campaign' => $your_sniply_campaign_id);
// Using Curl
$ch = curl_init($sniply_linksapi_uri);
curl_setopt_array($ch, array(CURLOPT_POST => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HTTPHEADER => array('Authorization: Bearer ' . $auth_token_sniply, 'Content-Type: application/json'), CURLOPT_POSTFIELDS => json_encode($postData)));
// Sending and checking for error
$response = curl_exec($ch);
if ($response === FALSE) {
    die(curl_error($ch));
}
// Decode the response
$responseData = json_decode($response, TRUE);
// Get the link from snip.ly
$sniply_link = $responseData['href'];
/* #3 Send Snip.ly link to Buffer */
$buffer = new BufferPHP($your_buffer_token);
$buffer_data = array('profile_ids' => array());
for ($i = 0; $i <= count($your_buffer_profiles_ids); $i++) {
    $buffer_data['profile_ids'][] = $your_buffer_profiles_ids[$i];
}
$buffer_data['text'] = $article_title;
$buffer_data['media'] = array('link' => $sniply_link, 'description' => $article_excerpt, 'title' => $article_title, 'picture' => $article_image);
$ret = $buffer->post('updates/create', $buffer_data);
var_dump($ret);