-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpbundle.php
More file actions
123 lines (104 loc) · 2.66 KB
/
phpbundle.php
File metadata and controls
123 lines (104 loc) · 2.66 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
# v1.2
class Json {
private $data;
private $file;
function __construct($file)
{
$this->file = $file;
$this->data = json_decode(file_get_contents($file), true);
}
public function get($item) {
if (isset($this->data[$item])) {
if ($this->data[$item] === null) {
return ["error", "null"];
} else {
return $this->data[$item];
}
} else {
return ["error", "undefined_key"];
}
}
public function getall() {
return $this->data;
}
public function set($key, $value) {
$this->data[$key] = $value;
}
public function remove($key) {
if (isset($this->data[$key])) {
unset($this->data[$key]);
}
}
public function save($data) {
file_put_contents($this->file, json_encode($data, JSON_PRETTY_PRINT));
}
public function exists($key) {
return isset($this->data[$key]);
}
public function count() {
return count($this->data);
}
public function clear() {
$this->data = [];
}
}
class Open {
private $file;
private $type;
function __construct($file, $type = null) {
$this->file = $file;
$this->type = $type;
}
function read() {
return file_get_contents($this->file, true);
}
function write($content) {
$this->create();
$w_file = fopen($this->file, "w");
if ($w_file === false) {
echo "Error opening file.";
return false;
}
if (fwrite($w_file, $content) === false) {
echo "Error writing to file.";
fclose($w_file);
return false;
}
fclose($w_file);
return true;
}
function json($value = null) {
if ($this->type == "r") {
return (new Json($this->file))->getall();
} elseif ($this->type == "w") {
$this->create();
return (new Json($this->file))->save($value);
}
}
function create() {
$folder = dirname($this->file);
if (!is_dir($folder)) {
if (!mkdir($folder, 0777, true)) {
echo "Error creating folder.";
return false;
}
}
}
}
function printt($value) {
if (is_array($value)) {
print_r($value);
} else {
echo $value;
}
}
function p($value) {
printt($value);
}
function reloadjs() {
printt("<script>window.location.reload();</script>");
}
function js($java_script) {
printt("<script>{$java_script}</script>");
}