-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVkConfig.php
More file actions
50 lines (44 loc) · 1.1 KB
/
VkConfig.php
File metadata and controls
50 lines (44 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Created by PhpStorm.
* User: DnAp
* Date: 21.08.2016
* Time: 12:08
*/
class VkConfig
{
public $tokenFileName = __DIR__ . '/.accessToken';
protected $key;
protected $host;
/**
* VkConfig constructor.
* @param $host
*/
public function __construct($host)
{
$this->host = $host;
}
public function getKey()
{
if ($this->key)
return $this->key;
if (is_file($this->tokenFileName)) {
return trim(file_get_contents($this->tokenFileName));
}
return null;
}
public function newKey(Vk $vk)
{
if(isset($_POST['token'])) {
file_put_contents($this->tokenFileName, $_POST['token']);
$this->key = $_POST['token'];
$vk->access_token = $_POST['token'];
return false;
}
$return = '<a href="'.htmlspecialchars($vk->get_code_token()).'" target="_blank">Get new token</a>'.
'<form method="post" target="_blank" action="'.$this->host.'">
<input name="token"/><input type="submit">
</form>';
return $return;
}
}