Files
wordpress-preseed/wp-content/plugins/shariff/services/shariff-buffer.php
2019-10-24 00:12:05 +02:00

76 lines
5.3 KiB
PHP

<?php
/**
* Will be included in the shariff.php only, when Buffer is requested as a service.
*
* @package Shariff Wrapper
*/
// Prevent direct calls.
if ( ! class_exists( 'WP' ) ) {
die();
}
// Check if we need the frontend or the backend part.
if ( isset( $frontend ) && 1 === $frontend ) {
// Service URL.
$service_url = esc_url( 'https://buffer.com/add' );
// Build the button URL.
$button_url = $service_url . '?url=' . $share_url . '&text=' . $share_title;
// Set the Colors (Hexadecimal including the #).
$main_color = '#168eea';
$secondary_color = '#329ced';
$wcag_color = '#0C5B97';
// SVG icon.
$svg_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path fill="' . $main_color . '" d="M91-37.4V-52l1.8 1 24 11.2c1.7.8 3.3.7 4.9 0l24-11.2 1-.4c.9-.6 1-1.3 0-1.8l-3.5-1.7a6.2 6.2 0 0 0-6.2 0l-15.1 7.1c-1.7.8-3.4.9-5.1 0-4.7-2.3-9.5-4.3-14.2-6.7-2.7-1.4-5.3-1.7-8-.1-1.1.7-2.3 1.2-3.5 1.7v-14.3l25 11.6c2.2 1.1 4.2 1 6.3 0l23.5-11c.6-.3 1.5-.4 1.4-1.3 0-.8-.8-1-1.3-1.2l-24.5-11.5a5.2 5.2 0 0 0-4.4-.1L91-68.5v-16.2c0-1.1.2-1.3 1.3-1.3h88.9l-.1 2.3v59.6c-.1 1.1.5 1.5 1.6 1.5h9.4c1 0 1.5-.4 1.5-1.5v-4l1.3 1.2c7.9 7.7 21 6.9 27.8-1.8s7-24.2.5-33.3c-6.7-9.3-20.8-10.6-28.4-2.4-.3.3-.4.8-1.2.6V-86H422c1.2 0 1.5.3 1.5 1.5-.1 5.4 0 10.7 0 16.1-5.8-.3-10 2.7-14.2 6.6v-3.8c0-1.4-.4-2-1.8-1.9h-6.2c-4 0-4 0-4 4.1v39.1c0 1.3.4 1.8 1.6 1.8h8c2.3 0 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4-1.9c3-1.8 5.7-1.4 8.8.1 5.3 2.7 10.6 5 15.9 7.5 2 .9 3.7.9 5.6 0 5.6-2.7 11.3-5.2 16.9-8a7.2 7.2 0 0 1 6.9 0c1.2.8 2.6 1.3 3.9 2 1 .6 1 1.3 0 2l-1 .4-26.9 12.5c-1.8.9-3.6.9-5.3 0L2.2 33.6c-.7-.3-1.2-.8-1.9-1v-1z"/></svg>';
// Backend available?
$backend_available = 1;
// Button alt label.
$button_title_array = array(
'bg' => 'Сподели в buffer',
'cs' => 'Sdílet na buffer',
'da' => 'Del på buffer',
'de' => 'Bei buffer teilen',
'en' => 'Share on buffer',
'es' => 'Compartir en buffer',
'fi' => 'Jaa bufferissä',
'fr' => 'Partager sur buffer',
'hr' => 'Podijelite na buffer',
'hu' => 'Megosztás bufferen',
'it' => 'Condividi su buffer',
'ja' => 'buffer上で共有',
'ko' => 'buffer에서 공유하기',
'nl' => 'Delen op buffer',
'no' => 'Del på buffer',
'pl' => 'Udostępnij przez buffer',
'pt' => 'Compartilhar no buffer',
'ro' => 'Partajează pe buffer',
'ru' => 'Поделиться на buffer',
'sk' => 'Zdieľať na buffer',
'sl' => 'Deli na buffer',
'sr' => 'Podeli na buffer',
'sv' => 'Dela på buffer',
'tr' => 'buffer\'ta paylaş',
'zh' => '在buffer上分享',
);
} elseif ( isset( $backend ) && 1 === $backend ) {
// Get share counts.
$buffer = sanitize_text_field( wp_remote_retrieve_body( wp_remote_get( 'https://api.bufferapp.com/1/links/shares.json?url=' . $post_url ) ) );
// Decode the json response.
$buffer_json = json_decode( $buffer, true );
/**
* Stores results.
* Records errors, if enabled (e.g. request from the status tab).
*/
if ( isset( $buffer_json['shares'] ) ) {
$share_counts['buffer'] = intval( $buffer_json['shares'] );
} elseif ( isset( $record_errors ) && 1 === $record_errors ) {
$service_errors['buffer'] = $buffer;
}
}; // End if backend.