Файл: sys/inc/classes/class.OAuth.php
Строк: 55
<?php
class OAuth
{
private $ident = false;
private $settings;
private $token;
private $OAuthMethod = array(
'vk' => array(
'authorize' => 'https://oauth.vk.com/authorize',
),
);
public function __construct($settings = false, $token = false)
{
$this->settings = $settings;
$this->token = $token;
}
public function getData($method = 'audio.search', $query = '')
{
if ($this->token) {
$params = array(
'access_token' => $this->token,
);
$params = array_merge($query, $params);
return $this->getJsonData('https://api.vk.com/method/' . $method . '?' . urldecode(http_build_query($params)));
}
}
public function getToken()
{
$data = array(
'client_id' => $this->settings['vk']['client_id'],
'client_secret' => $this->settings['vk']['client_secret'],
'code' => $_GET['code'],
'redirect_uri' => $this->settings['redirect_url'],
);
$token = $this->getJsonData('https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($data)));
return $token;
}
public function getLink($scope = '')
{
$data = array(
'client_id' => $this->settings['vk']['client_id'],
'redirect_uri' => $this->settings['redirect_url'],
'response_type' => 'code',
'scope' => $scope,
);
return $this->OAuthMethod['vk']['authorize'] . '?' . urldecode(http_build_query($data));
}
private function getJsonData($url)
{
$data = @file_get_contents(str_replace('&', '&', $url));
if ($data)
return json_decode($data, true);
}
private function getCurlData($url, $data)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, str_replace('&', '&', $url));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, urldecode(http_build_query($data)));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
}