-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGroup.php
108 lines (99 loc) · 2.63 KB
/
Group.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Vktote\Settings;
use Vktote\Config\Config;
use Vktote\Config\Vk;
use Vktote\DataBase\Models\VkgroupModel;
use Vktote\Settings\File\File;
/**
* Group class
*
* @author aidsoul <[email protected]>
*/
class Group
{
/**
* Send message function
*
* @param integer $status
* @param string $pathIni
* @param string $pathPhp
*
* @return array<string>
*/
private function send(int $status, string $pathIni): array
{
return [
'status' => $status,
'file' => $_POST['fileName'],
'pathIni' => $pathIni
];
}
/**
* Create group function
*
* @return void
*/
public function create(): string
{
$send = [];
$file = new File();
$file->set($_POST['fileName']);
if (!is_dir($file->folder)) {
mkdir($file->folder);
}
if (!file_exists($file->configPath)) {
file_put_contents($file->configPath, include SETTINGS_PATTERN . '/PatternIni.php');
$send = $this->send(1, $file->configPath);
} else {
$send = $this->send(0, $file->configPath);
}
return json_encode($send);
}
/**
* Check exist file function
*
* @param string $file
* @param integer $status
* @return void
*/
private function checkFileExist(string $file, int $status): void
{
if (!file_exists($file)) {
die(json_encode(['status' => $status, 'name' => $file]));
}
}
/**
* Delete group function
*
* @param string $dirDelete
* @return array
*/
public function delete(string $dirName): string
{
$file = new File();
$file->set($dirName);
$ret = [];
if (is_dir($file->folder)) {
//check if exist ini file
$this->checkFileExist($file->configPath, 4);
try {
// delete group from database
Config::set($file->iniFullPath);
$vk = new VkgroupModel();
if ($idGroup = $vk->check(Vk::get()->idGroup)) {
$vk->remove($idGroup);
} else {
die(json_encode(['status' => 3, 'name' => Vk::get()->idGroup]));
}
} catch (\Exception $e) {
die(json_encode(['status' => 2]));
}
unlink($file->configPath);
rmdir($file->folder);
$ret = ['status' => 1, 'name' => 0];
} else {
$ret = ['status' => 0, 'name' => $file->folder];
}
return json_encode($ret);
}
}