| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
|
| 4 |
|
| 5 |
class pinterestNetwork extends mbNetwork |
| 6 |
{ |
| 7 |
protected $network = 'pinterest'; |
| 8 |
protected $icon = 'fa-pinterest'; |
| 9 |
protected $priority = 'readmore'; |
| 10 |
protected $color = '#cb2027'; |
| 11 |
|
| 12 |
public function __construct() |
| 13 |
{ |
| 14 |
parent::__construct(); |
| 15 |
|
| 16 |
$this->label = __('Share', 'mbsocial'); |
| 17 |
$this->share_url = 'https://www.pinterest.com/pin/create/bookmarklet/?media={img}&url={url}&is_video=false&description={title}'; |
| 18 |
$this->count_api = 'https://api.pinterest.com/v1/urls/count.json?url={url}'; |
| 19 |
$this->profile_url = 'http://www.pinterest.com/{profile}'; |
| 20 |
$this->countable = true; |
| 21 |
$this->return_var = 'count'; |
| 22 |
$this->popup_dimensions = array(750, 500); |
| 23 |
} |
| 24 |
|
| 25 |
public function remoteRequest($url) |
| 26 |
{ |
| 27 |
$response = wp_remote_get($url); |
| 28 |
|
| 29 |
if (is_wp_error($response) || $response['response']['code'] != 200) { |
| 30 |
return false; |
| 31 |
} |
| 32 |
else { |
| 33 |
$result = wp_remote_retrieve_body($response); |
| 34 |
} |
| 35 |
|
| 36 |
// remove the callback wrapper. |
| 37 |
$result = str_replace("receiveCount(","",$result); |
| 38 |
$result = substr($result,0,(strlen($result) -1) ); // remove last char. |
| 39 |
$json = json_decode($result, true); |
| 40 |
|
| 41 |
if (isset($json["count"])) |
| 42 |
return $json["count"]; |
| 43 |
|
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
} |
| 48 |
|