· 9 years ago · Nov 29, 2016, 10:52 PM
1<?PHP
2
3// Hook class
4class Hook {
5
6 /*
7 Created by James Walston, Some rights are reserved.
8
9 DISCLAIMER: Hook was made for educational purposes
10 only, and does not encourage those whom wish to
11 abuse it. Discrepancy is advised.
12 */
13
14 # Variables
15 public $table;
16 public $row;
17 public $errors;
18 public $argsc;
19
20 // General commands
21 # Initiates class construction
22 public function __construct() {
23 $this->table = [];
24 $this->row = 0;
25 $this->argsc = 0;
26 $this->errors = 0;
27 }
28
29 # Allows new hooks
30 public function Add($name, $args) {
31 $row = $this->row;
32 $this->row++;
33 $this->argsc++;
34
35 # If name already exists
36 if(in_array($name, $this->table)) {
37 echo "[ERROR]: Failed to create hook. (Hook exists)";
38
39 ++$this->errors;
40 }
41
42 # If no name
43 if(empty($name)) {
44 echo "[ERROR]: Failed to create hook. (No name entered)";
45
46 ++$this->errors;
47 }
48
49 else return $this->table[$row] = ["name" => $name, "args" => [implode("|", $args)]];
50
51 }
52
53 # Removes hook
54 public function Remove() {
55 $row = $this->row;
56
57 $this->table[$row] = "";
58
59 # If the row is negative
60 if($row < 0) {
61 $this->row = 0;
62 }
63
64 else return $row--;
65
66 }
67
68 // Extensive commands
69 # Allows extra arguments
70 public function Argument($args) {
71 $row = $this->row;
72 $tArgs = $this->argsc;
73 $this->args++;
74
75 return $this->table[$row]["args"][$tArgs] = implode("|", $args);
76 }
77
78 # Strips the joints in args
79 public function Strip() {
80 $row = $this->row;
81 $tArgs = $this->argsc;
82 $i = 0;
83
84 # Sets a loop to get rows
85 for($i = 0; $i < $tArgs; $i++) {
86 return explode("|", $this->table[$row]["args"][$i]);
87 }
88
89 return $this->table[$row]["args"];
90
91 }
92
93 # Gets current row
94 public function Row() {
95 $row = $this->row;
96
97 # If nothing is in table
98 if(empty($this->table)) {
99 echo "[ERROR]: Failed to get row (Table empty)";
100
101 ++$this->errors;
102 }
103
104 else return $this->table[$row];
105
106 }
107
108 # Verifies hook status
109 public function Verify($name) {
110 $row = $this->row;
111 $i = 0;
112
113 $start = 1;
114
115 # Backup if
116 if($start) {
117
118 # Sets for loop to count rows
119 for($i = 0; $i < $row; $i++) {
120
121 # If name does not exist
122 if(!in_array($name, $this->table[$i])) {
123 echo "[Hook]: Name does not exist in row: " . $row;
124
125 return $start = 1;
126 }
127
128 # If name exists
129 elseif(in_array($name, $this->table[$i])) {
130 echo "[Hook]: Name exists in row: " . $row;
131
132 return $start = 0;
133 }
134
135 }
136
137 }
138
139 }
140
141 # Gets row number
142 public function RowNum() {
143 $row = $this->row;
144
145 # If nothing is in table
146 if(empty($this->table)) {
147 echo "[ERROR]: Failed to get row (Table empty)";
148
149 ++$this->errors;
150 }
151
152 else return $row;
153
154 }
155
156 # Gets args from hook
157 public function Args() {
158 $row = $this->row;
159
160 # If there are no args
161 if(empty($this->table[$row]["args"])) {
162 echo "[Hook]: There are no arguments.";
163 }
164
165 else return $this->table[$row]["args"];
166 }
167
168 // Custom commands
169 # Allows custom hook creation
170 public function HAdd($id, $name, $args) {
171
172 # If name is taken
173 if(in_array($name, $this->table)) {
174 echo "[ERROR]: Failed to create custom hook (Hook exists)";
175
176 ++$this->errors;
177 }
178
179 else return $this->table[$id] = ["name" => $name, "args" => implode("|", $args)];
180
181 }
182
183}
184
185$hook = new Hook();
186
187?>