| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
|
| 4 |
|
| 5 |
class vkontakteNetwork extends mbNetwork |
| 6 |
{ |
| 7 |
protected $network = 'vkontakte'; |
| 8 |
protected $priority = 'readmore'; |
| 9 |
protected $icon = 'fa-vk'; |
| 10 |
protected $color = '#4c75a3'; |
| 11 |
|
| 12 |
|
| 13 |
public function __construct() |
| 14 |
{ |
| 15 |
|
| 16 |
$this->label = __('Share', 'mbsocial'); |
| 17 |
$this->share_url = 'https://vkontakte.ru/share.php?url={url}'; |
| 18 |
$this->count_api = 'https://vk.com/share.php?act=count&url={url}'; |
| 19 |
$this->profile_url = 'https://vk.com/{profile}'; |
| 20 |
|
| 21 |
$this->countable = true; |
| 22 |
parent::__construct(); |
| 23 |
|
| 24 |
// count function vKontakteCount |
| 25 |
} |
| 26 |
|
| 27 |
public function remoteRequest($url) |
| 28 |
{ |
| 29 |
|
| 30 |
$response = wp_remote_get($url); |
| 31 |
|
| 32 |
if (is_wp_error($response) || $response['response']['code'] != 200) { |
| 33 |
return false; |
| 34 |
} |
| 35 |
else { |
| 36 |
$result = wp_remote_retrieve_body($response); |
| 37 |
} |
| 38 |
|
| 39 |
preg_match('/(\d+),\s+(\d+)/i', $result, $matches); |
| 40 |
if (isset($matches[2])) // 0 is both patterns, one is first number (not used?). |
| 41 |
{ $count = $matches[2]; |
| 42 |
return $count; |
| 43 |
} |
| 44 |
return 0; |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|