· 8 years ago · Nov 30, 2017, 10:42 AM
1<?php
2
3/**
4 * Garuda Framework Pro Edition 6.0
5 *
6 * @package GF-Pro
7 * @author Lamhot Simamora < lamhotsimamora36@gmail.com >
8 */
9
10namespace System;
11defined('sys_run_app') OR exit('403 You dont have permission to access / on this server...');
12
13 class GF_URL
14 {
15 public static function fullUrl()
16 {
17 (__DIR_NAME__=='') ? $_dir = '/' : $_dir = '/'.__DIR_NAME__."/";
18 return (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]".$_dir;
19 }
20 }
21
22 class GF_Requirements
23 {
24 public static function checkPHPVersion()
25 {
26 if (_phpVersion() < 7.0)
27 {
28 $o = new GF_Message();
29 exit($o->showError('8'));
30 }
31 }
32 }
33
34 class GF_Message
35 {
36 public static function showError($type,$parameter=null,$parameter1=null)
37 {
38 $GF_NOT_FOUND_STRING = 'GF Tidak dapat menemukan file ini ->'; $GF_R_M_C_V_L_H = "<font color='red'>'$parameter' </font> </br></br> Periksa kembali file"; $GF_MUST_BE_NOT_EMPTY ="Upzz, anda harus memasukkan <font color='red'> nama file"; $GF_CANNOT_FIND = "GF Tidak dapat menemukan"; if ($type=='1') {$parameter= str_replace("/", "\\", $parameter); $message = $GF_NOT_FOUND_STRING."<font color='red'>'$parameter' </font> Periksa kembali file tersebut !"; return self::template($message); } else if ($type=='1a') {$parameter= str_replace("/", "\\", $parameter); $message = $GF_NOT_FOUND_STRING." <font color='red'>'$parameter' </font> atau <font color='red'>'$parameter1' </font> Periksa kembali file tersebut !"; return self::template($message); } else if ($type=='1b') {$parameter= str_replace("/", "\\", $parameter); $message = $GF_MUST_BE_NOT_EMPTY." untuk tampilan/view </font>"; return self::template($message); } else if ($type=='1r') {$parameter= str_replace("/", "\\", $parameter); $message = $GF_MUST_BE_NOT_EMPTY." untuk Router </font>"; return self::template($message); } else if ($type=='RU') {$parameter= str_replace("/", "\\", $parameter); $message = $GF_NOT_FOUND_STRING.$GF_R_M_C_V_L_H." Router tersebut !"; return self::template($message); } else if ($type=='CU') {$parameter= str_replace("/", "\\", $parameter); $message = $GF_NOT_FOUND_STRING.$GF_R_M_C_V_L_H." Controller tersebut !"; return self::template($message); } else if ($type=='MU') {$parameter= str_replace("/", "\\", $parameter); $message = $GF_NOT_FOUND_STRING.$GF_R_M_C_V_L_H." Model tersebut !"; return self::template($message); } else if ($type=='HU') {$parameter= str_replace("/", "\\", $parameter); $message = $GF_NOT_FOUND_STRING.$GF_R_M_C_V_L_H." Helper tersebut !"; return self::template($message); } else if ($type=='LU') {$parameter= str_replace("/", "\\", $parameter); $message = $GF_NOT_FOUND_STRING.$GF_R_M_C_V_L_H." Library tersebut !"; return self::template($message); } else if ($type=='2') {$message = "GF Tidak dapat membuat VIEW"; return self::template($message); } else if ($type=='3') {$message = "Parameter ini -> <font color='red'>'$parameter'</font> haruslah sebuah <font color='green'>function()</font> bukan STRING atau Integer atau Array"; return self::template($message); } else if ($type=='3a') {$message = "Parameter ini -> <font color='red'>'$parameter'</font> haruslah sebuah nama dari <font color='green'>CLASS</font> bukan Integer atau Array"; return self::template($message); } else if ($type=='3b') {$message = "Parameter ini -> <font color='red'>'$parameter'</font> Haruslah Sebuah Function atau Nama dari view "; return self::template($message); } else if ($type=='MODELNOTFOUND') {$message = " Jika anda mengaktifkan database maka <font color='red'>Anda harus membuat model terlebih dahulu</font>"; return self::template($message); } else if ($type=='4') {$message = "<font color='red'>CLASS</font> tidak ditemukan !, Anda harus membuat nama class <font color='red'>'$parameter'</font> terlebih dahulu di dalam controller ! Secara otomatis maka GF akan menjalankan Constructor class <font color='red'>'$parameter'</font> !"; return self::template($message); } else if ($type=='5') {$message = $GF_CANNOT_FIND." CLASS -> <font color='red'>'$parameter'</font> Buat CLASS tersebut didalam <font color='green'>CONTROLLER</font> atau periksa nama CLASS"; return self::template($message); } else if ($type=='5A') {$message = $GF_CANNOT_FIND." -> <font color='red'>CLASS '$parameter'</font> Buat CLASS tersebut didalam <font color='green'>MODEL</font> atau periksa nama CLASS"; return self::template($message); } else if ($type=='6') {$message = $GF_CANNOT_FIND." halaman error ini -> <font color='red'>'$parameter'</font>"; return self::template($message); } else if ($type=='7') {$message = $GF_CANNOT_FIND." function() ini -> <font color='red'>'$parameter'</font>"; return self::template($message); } else if ($type=='8') {$message = "Maaf GF Hanya dapat berjalan di -><font color='red'>PHP Version 7.0 or 7.1 </font>"; return self::template($message); } else if ($type=='any') {$message = $GF_CANNOT_FIND." <font color='red'>function() atau halaman VIEW</font>"; return self::template($message); } else if ($type=='GF') {$message = "Maaf Data GET dengan Parameter Tidak Tepat !"; return self::template($message); } else if ($type=='any1') {$message = $GF_CANNOT_FIND." function -> <font color='red'>$parameter</font> di dalam CLASS -> <font color='green'>$parameter1</font> , Periksa function tersebut ! "; return self::template($message); } else if ($type=='9') {$message = "Anda harus memasukkan parameter Pretty GET pada -> <font color='red'>'$parameter'</font> Dengan menggunakan karakter pemisah <font color='green'>'/'</font> {Tanpa Tanda Petik 1} "; return self::template($message); } else if ($type=='ConnectDBError') {$message = "GF tidak dapat terhubung Ke<font color='red'> Database Server</font>, Periksa kembali koneksi dan informasi database anda ! -> <hr><hr><font color='red'>'$parameter'</font>"; return self::template($message); } else if ($type=='PDO_DNS') {$message = "Maaf untuk class <font color='green'>PDO</font> hanya support DSN database <font color='red'>MySQl</font>, Silahkan anda tambahkan sendiri jika ingin menggunakan database lainnya."; return self::template($message); } else if ($type=='CLASS_WRONG') {$message = "Maaf sepertinya anda lupa mengganti class <font color='green'>Database</font> yang digunakan, silahkan periksa kembali"; return self::template($message); } else if ($type=='QueryError') {$message = "Terjadi Kesalahan Pada Saat Menjalankan Query -> <font color='red'>'$parameter'</font> atau Periksa Koneksi Database Anda ! <hr><hr><font color='red'>'$parameter1'</font>"; return self::template($message); } else if ($type=='selectWhere') {$message = "Pada Query Select Where, Nilai limit-> <font color='red'>'$parameter'</font> haruslah bernilai integer <hr><hr>"; return self::template($message); } else if ($type=='QueryEmpty') {$message = "<font color='red'>Query tidak ditemukan !</font> Masukkan Query terlebih dahulu !"; return self::template($message); } else if ($type=='QueryEmpty') {$message = "<font color='red'>Query tidak ditemukan !</font> Masukkan Query terlebih dahulu !"; return self::template($message); } else if ($type=='MaxPrettyGEt') {$message = "Maximum Pretty GET hanya <font color='red'>12</font> ! Request parameter -> <font color='green'>$parameter</font>"; return self::template($message); } else if ($type=='ME') {$message = "<font color='red'>Anda harus memasukkan nama class didalam parameter model </font>"; return self::template($message); } else if ($type=='CE') {$message = "<font color='red'>Anda harus memasukkan nama class didalam parameter controller </font>"; return self::template($message); } else if ($type=='MaxPost') {$message = "Maximum POST dari form input hanya <font color='red'>13</font> ! <font color='green'>$parameter</font>"; return self::template($message); } else if ($type=='FILES_NOT_SET') {$message = '<font color="red"> $_FILES['.$parameter.']</font> is not set ! Check in your FORM !'; return self::template($message); } else if ($type=='VALUE_COMPRESS_IMAGE') {$message = 'Value compress image -> <font color="red">'.$parameter.'</font> should be an integer !'; return self::template($message); } else if ($type=='DB_MAX_CHECK_ID') {$message = 'Maximum parameter function checkId() only -> <font color="red">5 column </font>'; return self::template($message); } else if ($type=='ROUTER_NULL') {$message = 'File <font color="red">Router</font> tidak ditemukan ! Buat Terlebih Dahulu File Router ! Lokasi -> <font color="green">"app/config/config.php"</font> { $_router_app }'; return self::template($message); } else if ($type=='Route_One_Empty') {$message = 'Anda harus memasukkan nama <font color="red">View</font> atau membuat <font color="red">function callback</font>'; return self::template($message); } else if ($type=='Route_One_Int') {$message = 'Parameter ini <font color="red">'.$parameter.'</font> haruslah sebuah <font color="green">View</font> atau <font color="green">Function Callback</font>'; return self::template($message); } else {return true;}
39
40 }
41
42 private static function template($value)
43 {
44 e("<hr>"._setImageBase64(__SYSTEM_DIR__.__GF_Image_Error__)."</br><hr> <h2> <center><code>$value</code></center></h2><hr></br></br></br> <center><code><u><h3>Garuda Framework Professional</h3></u></code></center>");
45 }
46
47 }
48
49use GF_Text\HTML_Generator;
50class PrettyGET
51{
52 private $uri; private $count_line; private $first_line; private $data = array(); private $user_param=true; function __construct($str,$type,$replaceType=null) {if ($type == true) {$this->uri = (strtolower(trim($str))); $this->user_param = false; } else if ($type==false) {$p = new HTML_Generator($str); $text = $p->getText(); $this->uri = $text; } if ($replaceType==true) {$this->uri = str_replace("#", "", $this->uri); $this->uri = str_replace("{", "", $this->uri); $this->uri = str_replace("}", "", $this->uri); } if ($this->checkLastLine($this->uri)) {$this->uri= rtrim($this->uri,"/"); } $this->countLine(); $this->setFirstLine(); } public function getCountLine() {return $this->count_line; } private function countLine() {$this->count_line =substr_count($this->uri, '/'); return $this->count_line; } private function checkLastLine($uri) {if (empty($uri)) {return false; } else {$check_last_line = $uri[strlen($uri) - 1]; return $check_last_line =='/' ? true : false; } } public function getUri() {return $this->uri; } private function checkLength() {return strlen($this->uri); } private function setFirstLine() {$r = explode('/',$this->uri); if ($this->user_param==false) {$this->first_line = rtrim($r[0]); } else {$this->first_line = $r[0]; } } public function getFirstLine() {return $this->first_line; } public function getData() {return array_map('trim', $this->data); } public function parseUri() {$result_uri = explode('/',$this->uri); $count_uri = count($result_uri); if ($count_uri>1) {if ($this->count_line==1) {$this->data = array($result_uri[0],$result_uri[1]); return true; } else if ($this->count_line==2) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2]); return true; } else if ($this->count_line==3) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3]); return true; } else if ($this->count_line==4) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4]); return true; } else if ($this->count_line==5) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5]); return true; } else if ($this->count_line==6) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6]); return true; } else if ($this->count_line==7) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7]); return true; } else if ($this->count_line==8) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7],$result_uri[8]); return true; } else if ($this->count_line==9) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7],$result_uri[8],$result_uri[9]); return true; } else if ($this->count_line==10) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7],$result_uri[8],$result_uri[9],$result_uri[10]); return true; } else if ($this->count_line==11) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7],$result_uri[8],$result_uri[9],$result_uri[10],$result_uri[11]); return true; } else if ($this->count_line==12) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7],$result_uri[8],$result_uri[9],$result_uri[10],$result_uri[11],$result_uri[12]); return true; } else {return false; } } }
53}
54
55 use GF_Interface\Cookie_Session;
56
57 class GF_Router extends GF_File implements Cookie_Session
58 {
59 private static $_GET_Parameter = __URI_GET_PARAMETER__;
60 private static $modeAPI = false;
61
62 private static $_GET_Request,$data_session,$data_cookie,$defaultHeader = array();
63
64 private static $header = array("Access-Control-Allow-Origin: "
65 ,"Access-Control-Allow-Credentials: "
66 ,"Access-Control-Allow-Methods: "
67 ,"Access-Control-Max-Age: "
68 ,"Access-Control-Allow-Headers: "
69 ,"Content-Length: 0"
70 ,"Content-Type: text/plain"
71 ,"HTTP/1.1 403 Access Forbidden");
72
73
74 public static function setHeader($i=false)
75 {
76 if ($i=false)
77 {
78 $i=1;
79 }
80 else if ($i >= count(self::$header))
81 {
82 return false;
83 }
84 header(self::$header[$i]);
85 }
86
87 public static function enabledApi()
88 {
89 self::$modeAPI = true;
90 }
91
92 public static function disabledApi()
93 {
94 self::$modeAPI = false;
95 }
96
97
98
99 private static function defaultHeader()
100 {
101 if (self::$modeAPI==false)
102 {
103 header(self::$header[0].__full_url__);
104 header(self::$header[1]." true");
105 }
106 else if (self::$modeAPI==true)
107 {
108 header(self::$header[0]." *");
109 }
110 }
111
112 public static function setupHeader($header=null)
113 {
114 if ($header==null)
115 {
116 self::defaultHeader();
117 }
118 else if (is_array($header))
119 {
120 for ($i=0; $i < count($header) ; $i++)
121 {
122 header($header[$i]);
123 }
124 }
125 else
126 {
127 self::defaultHeader();
128 }
129
130 }
131
132 public static function getAllHeader()
133 {
134 return self::$header;
135 }
136
137 private static function countLine($str)
138 {
139 return substr_count($str, '/');
140 }
141
142 private static function checkLastLine($uri)
143 {
144 try
145 {
146 if (empty($uri)) {return $uri; } else {$check_last_line = $uri[strlen($uri) - 1];
147 if ($check_last_line =='/' )
148 {
149 return rtrim($uri,"/"); } else {return $uri; } }
150 }
151 catch(Throwable $er) {}
152 }
153
154 private static function cleanUrl($url)
155 {
156 return strtolower(trim($url));
157 }
158 public static function checkSession($key='')
159 {
160 return (isset($_SESSION[$key])) ? true : false;
161 }
162 public static function newSession($key='',$val='')
163 {
164 if (! empty($key) && ! empty($val))
165 {
166 $_SESSION[$key] = $val;
167 self::$data_session[$key] = $val;
168 return true;
169 }
170 else if (is_array($key) || is_array($val))
171 {
172 return false;
173 }
174 else
175 {
176 return false;
177 }
178 }
179
180 public static function getAllSession()
181 {
182 return self::$data_session;
183 }
184
185 public static function getSession($key='')
186 {
187 if (isset($_SESSION[$key]))
188 {
189 return $_SESSION[$key];
190 }
191 else
192 {
193 return false;
194 }
195 }
196
197 public static function destroySession($key='')
198 {
199 if (! empty($key))
200 {
201 if (isset($_SESSION[$key]))
202 {
203 unset($_SESSION[$key]);
204 return true;
205 }
206 else
207 {
208 return false;
209 }
210 }
211 else
212 {
213 return false;
214 }
215 }
216
217 public static function newCookie($key='',$val='',$limit_time=null)
218 {
219 if (! empty($key) && ! empty($val))
220 {
221 _createCookie($key,$val,$limit_time);
222 self::$data_cookie[$key] = $val;
223 return true;
224 }
225 else if (is_array($key) || is_array($val))
226 {
227 return false;
228 }
229 else
230 {
231 return false;
232 }
233 }
234 public static function destroyCookie($key='')
235 {
236 if (! empty($key))
237 {
238 if (_checkCookie($key))
239 {
240 _destroyCookie($key);
241 return true;
242 }
243 else
244 {
245 return false;
246 }
247 }
248 else
249 {
250 return false;
251 }
252 }
253 public static function getAllCookie()
254 {
255 return self::$data_cookie;
256 }
257 public static function getCookie($key='')
258 {
259 if (isset($_COOKIE[$key]))
260 {
261 return $_COOKIE[$key];
262 }
263 else
264 {
265 return false;
266 }
267 }
268
269 public static function directTo($val)
270 {
271 $GF_URl = new GF_URl();
272 header('Location: '.$GF_URl->fullUrl().$val);
273 }
274
275 public static function RouteOne($user_uri,$function_user=null)
276 {
277 if (is_callable($user_uri) && ! is_string($user_uri))
278 {
279 trigger_error("Upzz the first parameter should be a string !",E_USER_ERROR);
280 exit;
281 }
282 self::setupHeader();
283
284 if (! __production__)
285 {
286 if (isset($_GET[self::$_GET_Parameter]))
287 {
288 $get_uri_ori = _replaceHtml(trim($_GET[self::$_GET_Parameter]));
289 if (! defined("__THIS_URL__"))
290 {
291 _def("__THIS_URL__",__full_url__.$get_uri_ori);
292 }
293 if (is_string($function_user))
294 {
295 $user_uri = str_replace("-","_",$user_uri);
296 self::setView($function_user,array($user_uri => $get_uri_ori));
297 exit;
298 }
299 else if ($function_user != null && ! is_string($function_user) && ! is_int($function_user))
300 {
301 call_user_func($function_user,$get_uri_ori);
302 exit;
303 }
304 else if ($function_user==null)
305 {
306 $msg_error = new GF_Message();
307 exit($msg_error->showError('Route_One_Empty'));
308 }
309 else if (is_int($function_user))
310 {
311 $msg_error = new GF_Message();
312 exit($msg_error->showError('Route_One_Int'));
313 }
314 else
315 {
316 return;
317 }
318 }
319 else
320 {
321 return;
322 }
323 }
324 else
325 {
326 if (__file_maintenance__ != null)
327 {
328 self::errorPage(__file_maintenance__);
329 exit();
330 }
331 }
332 }
333
334
335
336
337 public static function Route($user_uri=null,$function_user=null,$controller=null)
338 {
339 if (is_callable($user_uri) && ! is_string($user_uri))
340 {
341 trigger_error("Upzz the first parameter should be a string !",E_USER_ERROR);
342 exit;
343 }
344
345 self::setupHeader();
346
347 if (! __production__)
348 {
349 if (isset($_GET[self::$_GET_Parameter]))
350 {
351 $get_uri_ori = $_GET[self::$_GET_Parameter];
352 $user_uri_ori = $user_uri;
353
354 $user_parameter = new PrettyGET($user_uri_ori,true,true);
355 $get_parameter = new PrettyGET($get_uri_ori,false);
356
357 $count_user = $user_parameter->getCountLine();
358 $count_get = $get_parameter->getCountLine();
359
360 $first_line_user = $user_parameter->getFirstLine();
361 $first_line_get = $get_parameter->getFirstLine();
362
363 $get_parameter->parseUri();
364 $result = $user_parameter->parseUri();
365
366 $data_parameter = $get_parameter->getData();
367 $data_request = $user_parameter->getData();
368
369 $count_data1 = count($data_parameter);
370 $count_data2 = count($data_request);
371 $result_array = array();
372
373 _def("__THIS_URL__",__full_url__.$first_line_get);
374 if ($count_user > 0 && $count_get > 0 )
375 {
376 if ($first_line_user==$first_line_get)
377 {
378
379 if ($result==false)
380 {
381 $gf = new GF_Message();
382 $gf->showError("MaxPrettyGEt",$user_uri_ori);
383 exit;
384 }
385 for ($i=0; $i < $count_data2 ; $i++) {
386 $res = $data_parameter[$i] ?? false ;
387 $result_array[$data_request[$i]] = $res;
388 }
389 if ($function_user != null && ! is_string($function_user) && ! is_int($function_user) && $controller == null)
390 {
391
392 call_user_func($function_user,$result_array);
393 exit;
394 }
395 else if ($function_user != null && ! is_string($function_user) && ! is_int($function_user) && $controller != null)
396 {
397 if (class_exists($controller))
398 {
399
400 $controller = new $controller();
401 call_user_func($function_user,$result_array,$controller);
402 exit;
403 }
404 else
405 {
406 $msg_error = new GF_Message();
407 exit($msg_error->showError('5',$controller));
408 }
409 }
410 else if (is_string($function_user) && $function_user != null)
411 {
412 self::setView($function_user,$result_array);
413 exit;
414 }
415 }
416 }
417 else
418 {
419
420 $first_line_user = $user_parameter->getFirstLine();
421 $first_line_get = $get_parameter->getFirstLine();
422 $result_array = array();
423 for ($i=0; $i < $count_data2 ; $i++)
424 {
425 $res = $data_parameter[$i] ?? false ;
426 $result_array[$data_request[$i]] = $res;
427 }
428 if ($first_line_user == $first_line_get)
429 {
430 if ($function_user==null)
431 {
432 self::setView($first_line_user);
433 exit;
434 }
435 else if (is_string($function_user) && $function_user != null)
436 {
437 self::setView($function_user);
438 exit;
439 }
440 else if ($function_user != null && ! is_string($function_user) && ! is_int($function_user) && ! is_array($function_user))
441 {
442 call_user_func($function_user,$result_array);
443 exit;
444 }
445 else
446 {
447 $error = new GF_Message();
448 exit($error->showError('3b',$function_user));
449 }
450 }
451 }
452
453 }
454 else
455 {
456
457 $user_parameter = $user_uri;
458 if ($user_parameter=='/' && $function_user==null || $user_parameter=='')
459 {
460 if (is_string($function_user))
461 {
462 self::setView($function_user);
463 exit();
464 }
465 else
466 {
467 if ($function_user==null)
468 {
469 ! isset($error) ? $error = new GF_Message() : false ;
470 exit($error->showError('any',$function_user));
471 }
472 else
473 {
474 call_user_func($function_user);
475 exit();
476 }
477 }
478 }
479 }
480
481 }
482 else
483 {
484 if (__file_maintenance__ != null)
485 {
486 self::errorPage(__file_maintenance__);
487 exit();
488 }
489 }
490
491 }
492
493
494 public static function RouteToController($get_request=null,$class=null,$method=null)
495 {
496 $_p = "RouteToController -> Parameter haruslah sebuah string, bukan function callback !";
497 if (is_callable($get_request) && ! is_string($get_request))
498 {
499 trigger_error($_p,E_USER_ERROR);
500 exit;
501 }
502 if (is_callable($class) && ! is_string($class))
503 {
504 trigger_error($_p,E_USER_ERROR);
505 exit;
506 }
507
508 if (empty($get_request))
509 {
510 trigger_error("RouteToController -> Anda harus memasukkan URL parameter !",E_USER_ERROR);
511 exit;
512 }
513
514 self::setupHeader();
515
516 if (! __production__)
517 {
518 if (isset($_GET[self::$_GET_Parameter]))
519 {
520 $set_parameter = $_GET[self::$_GET_Parameter];
521 $set_parameter = htmlspecialchars($set_parameter);
522 $set_parameter = self::checkLastLine($set_parameter);
523 $get_request = self::cleanUrl($get_request);
524 $set_parameter = self::cleanUrl($set_parameter);
525 $get_ori_class = $class;
526 _def("__THIS_URL__",__full_url__.$set_parameter);
527 if (is_string($class))
528 {
529 $class = trim($class);
530 }
531
532 if ($set_parameter == $get_request)
533 {
534 if ($class==null)
535 {
536 try
537 {
538 $msg_error = new GF_Message();
539 class_exists($get_request) ? $get_request = new $get_request() && exit : exit($msg_error->showError('5',$get_request));
540 }
541 catch (Throwable $t)
542 {
543 $msg_error = new GF_Message();
544 exit($msg_error->showError('5',$get_request));
545 }
546 }
547 else if (class_exists($class) && is_string($class) && ! is_int($class))
548 {
549 if ($method==null)
550 {
551 $class = new $class();
552 exit();
553 }
554 else if (is_string($method))
555 {
556 $method = trim($method);
557
558 try
559 {
560 $class = new $class();
561 if (method_exists($class ,$method))
562 {
563 $class->$method();
564 exit;
565 }
566 else
567 {
568 $msg_error = new GF_Message();
569 exit($msg_error->showError('any1',$method,$get_ori_class));
570 }
571 }
572 catch (Throwable $t)
573 {
574 $msg_error = new GF_Message();
575 exit($msg_error->showError('any1',$method,$get_ori_class));
576 }
577 }
578 else
579 {
580 try
581 {
582 if (!is_int($method) && ! is_array($method))
583 {
584 $class = new $class();
585 call_user_func($method,$class);
586 exit();
587 }
588 else
589 {
590 $msg_error = new GF_Message();
591 exit($msg_error->showError('3',$method));
592 }
593
594 }
595 catch(Throwable $er)
596 {
597 echo "Something is wrong ! $method ->should be a call back function";
598 }
599 }
600 }
601 else
602 {
603 if (is_int($class) || is_array($class))
604 {
605 $msg_error = new GF_Message();
606 exit($msg_error->showError('3a',$class));
607 }
608 else
609 {
610 $msg_error = new GF_Message();
611 exit($msg_error->showError('5',$class));
612 }
613 }
614 }
615 }
616 }
617 else
618 {
619 if (__file_maintenance__ != null)
620 {
621 self::errorPage(__file_maintenance__);
622 exit();
623 }
624 }
625 }
626
627 public static function Model($class='',$data=array())
628 {
629 if (! empty($class))
630 {
631 if (class_exists($class))
632 {
633 if (count($data>0))
634 {
635 $class = new $class($data);
636 }
637 else if (count($data==0))
638 {
639 $class = new $class;
640 }
641 return $class;
642 }
643 else
644 {
645 $msg_error = new GF_Message();
646 exit($msg_error->showError('5A',$class));
647 }
648 }
649 else
650 {
651 $msg_error = new GF_Message();
652 exit($msg_error->showError('ME'));
653 }
654 }
655
656 public static function Controller($class='',$data=array())
657 {
658 if (! empty($class))
659 {
660 if (class_exists($class))
661 {
662 if (count($data>0))
663 {
664 $class = new $class($data);
665 }
666 else if (count($data==0))
667 {
668 $class = new $class;
669 }
670 return $class;
671 }
672 else
673 {
674 $msg_error = new GF_Message();
675 exit($msg_error->showError('5',$class));
676 }
677 }
678 else
679 {
680 $msg_error = new GF_Message();
681 exit($msg_error->showError('CE'));
682 }
683 }
684
685 public static function setModel($file='',$class='')
686 {
687 if (! empty($file))
688 {
689 $path = __MODEL_DIR__.$file.__ext_php__;
690 ! isset($check) ? $check = new GF_File() : false ;
691
692 if ($check->checkFile($path))
693 {
694 return require_once $path;
695 }
696 else
697 {
698 $msg_error = new GF_Message();
699 exit($msg_error->showError('MU',$path));
700 }
701 }
702 }
703
704 public static function setLibrary($file='')
705 {
706 if (! empty($file))
707 {
708 $path = __LIBRARY_DIR__.$file.__ext_php__;
709 ! isset($check) ? $check = new GF_File() : false ;
710
711 if ($check->checkFile($path))
712 {
713 return require_once $path;
714 }
715 else
716 {
717 $msg_error = new GF_Message();
718 exit($msg_error->showError('LU',$path));
719 }
720 }
721 }
722 public static function setController($file='')
723 {
724 if (! empty($file))
725 {
726 $path = __CONTROLLER_DIR__.$file.__ext_php__;
727 ! isset($check) ? $check = new GF_File() : false ;
728
729 if ($check->checkFile($path))
730 {
731 return require_once $path;
732 }
733 else
734 {
735 $msg_error = new GF_Message();
736 exit($msg_error->showError('CU',$path));
737 }
738 }
739
740 }
741 public static function setHelper($file='')
742 {
743 if (! empty($file))
744 {
745 $path = __HELPER_DIR__.$file.__ext_php__;
746 ! isset($check) ? $check = new GF_File() : false ;
747
748 if ($check->checkFile($path))
749 {
750 return require_once $path;
751 }
752 else
753 {
754 $msg_error = new GF_Message();
755 exit($msg_error->showError('HU',$path));
756 }
757 }
758
759 }
760 public static function setDatabase($file='',$data1=null,$data2=null)
761 {
762 if (! empty($file))
763 {
764 $path = __DB_DIR__.$file.__ext_php__;
765 ! isset($check) ? $check = new GF_File() : false ;
766
767 if ($check->checkFile($path))
768 {
769 if ($data1 != null )
770 {
771 is_array($data1) ? extract($data1,EXTR_OVERWRITE) : '';
772
773 }
774 if ($data2 != null)
775 {
776 is_array($data2) ? extract($data2,EXTR_OVERWRITE) : '';
777
778 }
779 return require_once $path;
780 }
781
782 }
783
784 }
785 public static function setLanguage($file='')
786 {
787 if (! empty($file))
788 {
789 $path = __LANGUAGE_DIR__.$file.__ext_php__;
790 ! isset($check) ? $check = new GF_File() : false ;
791 return ($check->checkFile($path)) ? require_once $path : false;
792 }
793 }
794
795 public static function setHead($file='',$data_1=null,$data_2=null)
796 {
797 if (! empty($file))
798 {
799 $path_php = __VIEW_DIR__.strtolower($file).__ext_php__;
800 $path_html = __VIEW_DIR__.strtolower($file).__ext_html__;
801
802 if (file_exists($path_php))
803 {
804 is_array($data_1) ? extract($data_1,EXTR_OVERWRITE) : '';
805 is_array($data_2) ? extract($data_2,EXTR_OVERWRITE) : '';
806 return include $path_php;
807 }
808 else if (file_exists($path_html))
809 {
810 is_array($data_1) ? extract($data_1,EXTR_OVERWRITE) : '';
811 is_array($data_2) ? extract($data_2,EXTR_OVERWRITE) : '';
812 return include $path_html;
813 }
814 else
815 {
816 $msg_error = new GF_Message();
817 exit($msg_error->showError('1a',$path_php,$path_html));
818 }
819
820 }
821 }
822 public static function setView($file='',$data_1=null,$data_2=null)
823 {
824 if (! empty($file))
825 {
826 $path_php = __VIEW_DIR__.strtolower($file).__ext_php__;
827 $path_html = __VIEW_DIR__.strtolower($file).__ext_html__;
828
829 if (file_exists($path_php))
830 {
831 is_array($data_1) ? extract($data_1,EXTR_OVERWRITE) : '';
832 is_array($data_2) ? extract($data_2,EXTR_OVERWRITE) : '';
833 return require_once $path_php;
834 ob_clean();
835 }
836 else if (file_exists($path_html))
837 {
838 is_array($data_1) ? extract($data_1,EXTR_OVERWRITE) : '';
839 is_array($data_2) ? extract($data_2,EXTR_OVERWRITE) : '';
840 return require_once $path_html;
841 ob_clean();
842 }
843 $msg_error = new GF_Message();
844 exit($msg_error->showError('1a',$path_php,$path_html));
845 }
846 else
847 {
848 $msg_error = new GF_Message();
849 exit($msg_error->showError('1b',$file));
850 }
851
852 }
853
854 public static function setRouter($file='')
855 {
856 if (! empty($file))
857 {
858 $path = __ROUTER_DIR__.$file.__ext_php__;
859 ! isset($check) ? $check = new GF_File() : false ;
860
861 if ($check->checkFile($path))
862 {
863 return require_once $path;
864 }
865 else
866 {
867 $msg_error = new GF_Message();
868 exit($msg_error->showError('RU',$path));
869 }
870 }
871 else
872 {
873 $msg_error = new GF_Message();
874 exit($msg_error->showError('1r',$file));
875 }
876
877 }
878 public static function errorPage($file='')
879 {
880 empty($file) ? $path = __ERROR_DIR__.__404_Page__ : $path = __ERROR_DIR__.$file;
881 if (file_exists($path.__ext_php__))
882 {
883 return include $path.__ext_php__;
884 exit();
885 }
886 else if (file_exists($path.__ext_html__))
887 {
888 return include $path.__ext_html__;
889 exit();
890 }
891 else
892 {
893 $msg_error = new GF_Message();
894 exit($msg_error->showError('6',$file.__ext_html__." or ".$file.__ext_php__));
895 }
896 }
897
898 public static function getHost()
899 {
900 $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]/";
901 return $url;
902 }
903 }
904
905 class GF_File
906 {
907 protected static $path_file=false;
908
909 public static function setPath($val='')
910 {
911 if (self::checkFile(__STORAGE_DIR__.$val))
912 {
913 self::$path_file = __STORAGE_DIR__.$val;
914 return true;
915 }
916 else
917 {
918 return false;
919 }
920 }
921 public function deleteDir($path='')
922 {
923 if (! empty($path))
924 {
925 $path = __STORAGE_DIR__.$path;
926 if(is_dir($path) == TRUE)
927 {
928 $rootFolder = scandir($path);
929 if(sizeof($rootFolder) > 2)
930 {
931 foreach($rootFolder as $folder)
932 {
933 if($folder != "." && $folder != "..")
934 {
935 $this->deleteDir($path."/".$folder);
936 }
937 }
938 rmdir($path);
939 }
940 }
941 else
942 {
943 if(file_exists($path) == TRUE)
944 {
945 unlink($path);
946 }
947 }
948 }
949 }
950
951 public static function checkFile($path)
952 {
953 return file_exists($path) ? true : false;
954 }
955
956 public static function deleteFile()
957 {
958 return (file_exists(self::$path_file)) ? unlink(self::$path_file) && true : false;
959 }
960
961 public static function download($file=null)
962 {
963
964 if ($file != null)
965 {
966
967 header('Content-Description: File Transfer');
968 header('Content-Type: application/octet-stream');
969 header('Content-Disposition: attachment; filename="'.basename($file).'"');
970 header('Expires: 0');
971 header('Cache-Control: must-revalidate');
972 header('Pragma: public');
973 header('Content-Length: ' . filesize($file));
974 readfile($file);
975
976 }
977 else
978 {
979 if (self::$path_file == false)
980 {
981 return false;
982 }
983 $r = str_replace("/", "\\", self::$path_file);
984 if (file_exists($r))
985 {
986 header('Content-Description: File Transfer');
987 header('Content-Type: application/octet-stream');
988 header('Content-Disposition: attachment; filename="'.basename($r).'"');
989 header('Expires: 0');
990 header('Cache-Control: must-revalidate');
991 header('Pragma: public');
992 header('Content-Length: ' . filesize($r));
993 readfile($r);
994 }
995 else
996 {
997 return false;
998 }
999 }
1000
1001 }
1002
1003 public static function createDir($path='')
1004 {
1005 if (! empty($path))
1006 {
1007 return (mkdir(__STORAGE_DIR__.$path,0700, true)) ? true : false;
1008 }
1009 else
1010 {
1011 return false;
1012 }
1013 }
1014}
1015
1016 class GF_Upload extends GF_File
1017 {
1018 private static $file_upload, $extension_file, $maximum_size, $path_upload, $original_name;
1019
1020 private static $compress_image = 50;
1021
1022 private static $file_name_upload = false, $allow_upload = true, $type_file = false;
1023
1024 private static $image_only = array(".png", ".gif", ".jpg", ".bmp",".jpeg");
1025 private static $danger_file = array('.html','.php','.js','.exe','.php5','.php7','.htaccess');
1026
1027 private static $file_multiple=array();
1028
1029 private static $upload_multiple = false;
1030
1031 public static function setImageOnly($file_format=array())
1032 {
1033 self::$type_file = true;
1034 if (count($file_format)>0 && is_array($file_format))
1035 {
1036 self::$image_only = $file_format;
1037 }
1038 }
1039
1040 public static function setDangerFile($file_format = array())
1041 {
1042 if (count($file_format) > 0 && is_array($file_format))
1043 {
1044 self::$danger_file = $file_format;
1045 }
1046 }
1047
1048 private static function setOriginalFileName()
1049 {
1050 if (isset($_FILES[self::$file_upload]["name"]))
1051 {
1052 self::$original_name = $_FILES[self::$file_upload]["name"] ;
1053 }
1054 }
1055 public static function getOriginalFileName()
1056 {
1057 return self::$original_name;
1058 }
1059
1060 public static function setCompressImage($value=50)
1061 {
1062 if (is_int($value))
1063 {
1064 self::$compress_image = $value;
1065 }
1066 else
1067 {
1068 $gf = new GF_Message();
1069 exit($gf->showError("VALUE_COMPRESS_IMAGE",$value));
1070 }
1071 }
1072
1073 public static function setFileUpload($value)
1074 {
1075 if (is_array($value))
1076 {
1077 self::$file_upload = $value;
1078 }else{
1079 if (isset($_FILES[$value]))
1080 {
1081 self::$file_upload = $value;
1082 self::setOriginalFileName();
1083 self::setExtensionFile();
1084
1085 if (self::$type_file)
1086 {
1087 self::checkExtension() ? false : self::$allow_upload = false;
1088 }
1089 }
1090 else
1091 {
1092 self::$allow_upload = false;
1093 return false;
1094 }
1095 }
1096 }
1097
1098 public static function isImage()
1099 {
1100 if (self::$type_file)
1101 {
1102 if (in_array(self::$extension_file, self::$image_only))
1103 {
1104 self::$allow_upload = true;
1105 return true;
1106 }
1107 else
1108 {
1109 self::$allow_upload = false;
1110 return false;
1111 }
1112 }
1113 return true;
1114 }
1115
1116 public static function isEmpty()
1117 {
1118 if (empty($_FILES[self::$file_upload]["name"]))
1119 {
1120 self::$allow_upload = false;
1121 return false;
1122 }
1123 else
1124 {
1125 return true;
1126 }
1127 }
1128
1129 public static function setMaxSize($value)
1130 {
1131 self::$maximum_size = $value;
1132 }
1133
1134 public static function checkSize()
1135 {
1136 return ($_FILES[self::$file_upload]["size"] >= self::$maximum_size) ? true : false ;
1137 }
1138
1139
1140 public static function setFileName($value)
1141 {
1142 if (self::$allow_upload)
1143 {
1144 self::$file_name_upload = $value;
1145 return self::$file_name_upload;
1146 }
1147 else
1148 {
1149 return false;
1150 }
1151 }
1152
1153
1154 private static function setExtensionFile()
1155 {
1156 if (self::$allow_upload)
1157 {
1158 self::$extension_file = strtolower(".".pathinfo(basename($_FILES[self::$file_upload]["name"]),PATHINFO_EXTENSION));
1159 }
1160 else
1161 {
1162 return false;
1163 }
1164
1165 }
1166 public static function getExtension(){
1167 return self::$extension_file;
1168 }
1169
1170 private static function checkTypeFile()
1171 {
1172 return (self::$type_file==false) ? true : false;
1173 }
1174
1175
1176 public static function setMultipleUpload(){
1177 self::$upload_multiple = true;
1178 }
1179
1180 public static function setPath($dirname='')
1181 {
1182 if (self::$upload_multiple==false)
1183 {
1184 if (self::$allow_upload)
1185 {
1186 $dirname = $dirname."/";
1187
1188 if (! is_dir(__STORAGE_DIR__.$dirname))
1189 {
1190 if (parent::createDir($dirname));
1191 {
1192 if (! file_exists(__STORAGE_DIR__.$dirname."index.php"))
1193 {
1194 $files = fopen(__STORAGE_DIR__.$dirname."index.php","w");
1195 fwrite($files,"<?php exit('404 Page Not Found')");
1196 fclose($files);
1197 }
1198 if (self::$file_name_upload != false )
1199 {
1200 self::$path_upload = __STORAGE_DIR__.$dirname.self::$file_name_upload.self::$extension_file;
1201 }
1202 else
1203 {
1204 self::$path_upload = __STORAGE_DIR__.$dirname.basename($_FILES[self::$file_upload]["name"]);
1205 }
1206 }
1207 }
1208 else
1209 {
1210 if (self::$file_name_upload != false)
1211 {
1212 self::$path_upload = __STORAGE_DIR__.$dirname.self::$file_name_upload.self::$extension_file;
1213 }
1214 else
1215 {
1216 self::$path_upload = __STORAGE_DIR__.$dirname.basename($_FILES[self::$file_upload]["name"]);
1217 }
1218 }
1219 }
1220 }else{
1221 $dirname = $dirname."/";
1222 if (! is_dir(__STORAGE_DIR__.$dirname))
1223 {
1224 if (parent::createDir($dirname));
1225 {
1226 if (! file_exists(__STORAGE_DIR__.$dirname."index.php"))
1227 {
1228 $files = fopen(__STORAGE_DIR__.$dirname."index.php","w");
1229 fwrite($files,"<?php exit('404 Page Not Found')");
1230 fclose($files);
1231 }
1232 self::$path_upload = __STORAGE_DIR__.$dirname;
1233 }
1234 }else{
1235 self::$path_upload = __STORAGE_DIR__.$dirname;
1236 }
1237 }
1238 }
1239 public static function checkFileUpload()
1240 {
1241 return file_exists(self::$path_upload) ? true : false;
1242 }
1243 private static function checkExtension()
1244 {
1245 return (in_array(self::$extension_file, self::$image_only)) ? true : false ;
1246 }
1247
1248
1249 public static function do($function=null)
1250 {
1251 if (self::$upload_multiple)
1252 {
1253 $result=array();
1254 for ($i=0; $i < count(self::$file_upload) ; $i++)
1255 {
1256 $file = $_FILES[self::$file_upload[$i]]["name"];
1257
1258 $file_tmp = empty($_FILES[self::$file_upload[$i]]["name"]) ? null : $_FILES[self::$file_upload[$i]]["tmp_name"];
1259
1260 $result[$i]['name'] = self::$file_upload[$i];
1261 $result[$i]['original_filename'] = $file;
1262 $result[$i]['result'] = false;
1263
1264 if ($file_tmp != null)
1265 {
1266 $extension = strtolower(".".pathinfo(basename($file),PATHINFO_EXTENSION));
1267 $size = $_FILES[self::$file_upload[$i]]["size"];
1268 $result[$i]['size'] = $size;
1269 $result[$i]['extension'] = $extension;
1270 $file_name = self::$file_name_upload[$i] ? self::$file_name_upload[$i].$extension : $file;
1271 if ($size >= self::$maximum_size)
1272 {
1273 $result[$i]['result'] = false;
1274 $S_M = round(self::$maximum_size / 1000);
1275 $result[$i]['message'] = _upload_max_." ".$S_M." KB";
1276 continue;
1277 }
1278
1279 if (! self::$type_file)
1280 {
1281 if (! in_array($extension,self::$danger_file))
1282 {
1283 if (! file_exists(self::$path_upload.$file))
1284 {
1285
1286 if (move_uploaded_file($file_tmp, self::$path_upload.$file_name))
1287 {
1288 $result[$i]['result'] = true;
1289 $result[$i]['message'] = _upload_success_." ".$file;
1290 }else{
1291 $result[$i]['result'] = false;
1292 }
1293 }else{
1294 $result[$i]['message'] = _upload_exist_." ".$file;
1295 $result[$i]['result'] = false;
1296 }
1297 }else{
1298 $result[$i]['message'] = _upload_ignore_." ".$file;
1299 $result[$i]['result'] = false;
1300 continue;
1301 }
1302 }
1303 else
1304 {
1305 if (in_array($extension, self::$image_only))
1306 {
1307 if (! file_exists(self::$path_upload.$file))
1308 {
1309
1310 $res = _compressImage($file_tmp, self::$path_upload.$file_name, self::$compress_image);
1311 if ($res)
1312 {
1313 $result[$i]['result'] = true;
1314 $result[$i]['message'] = _upload_success_." ".$file;
1315 }
1316 }else{
1317 $result[$i]['message'] = _upload_exist_." ".$file;
1318 $result[$i]['result'] = false;
1319 }
1320 }else{
1321 $result[$i]['message'] = __upload_image__." ".$file;
1322 $result[$i]['result'] = false;
1323 }
1324 }
1325 }
1326 else{
1327 $result[$i]['result'] = false;
1328 }
1329 }
1330 return $result;
1331 }
1332 else{
1333 $file_name_temp;
1334 if (self::$file_name_upload != false)
1335 {
1336 $file_name_temp = self::$file_name_upload.self::$extension_file;
1337 }
1338 else
1339 {
1340 $file_name_temp = $_FILES[self::$file_upload]['name'];
1341 }
1342
1343 if (self::$allow_upload==false)
1344 {
1345 return false;
1346 }
1347 else if(empty(self::$path_upload))
1348 {
1349 if ( $function != null)
1350 {
1351 call_user_func($function,_upload_empty_);
1352 return;
1353 }
1354 else
1355 {
1356 return _upload_empty_;
1357 }
1358 }
1359 else if (! self::checkFileUpload())
1360 {
1361 if (! self::checkSize())
1362 {
1363 if (in_array(self::$extension_file, self::$danger_file))
1364 {
1365 if ($function!=null)
1366 {
1367 call_user_func($function,_upload_ignore_.self::$original_name);
1368 }
1369 else
1370 {
1371 return _upload_ignore_.self::$original_name;
1372 }
1373 }
1374 else
1375 {
1376 if (self::$type_file)
1377 {
1378 $compress = _compressImage($_FILES[self::$file_upload]['tmp_name'], self::$path_upload, self::$compress_image);
1379 if ($compress)
1380 {
1381 if ($function!=null)
1382 {
1383 call_user_func($function,_upload_success_.$file_name_temp);
1384 }
1385 else
1386 {
1387 return _upload_success_.$file_name_temp;
1388 }
1389 }
1390 else
1391 {
1392 if ($function!=null)
1393 {
1394 call_user_func($function,_upload_failed_);
1395 }
1396 else
1397 {
1398 return _upload_failed_;
1399 }
1400 }
1401 }
1402 else
1403 {
1404 if (move_uploaded_file($_FILES[self::$file_upload]['tmp_name'], self::$path_upload))
1405 {
1406 if ($function!=null)
1407 {
1408 call_user_func($function,_upload_success_.$file_name_temp);
1409 }
1410 else
1411 {
1412 return _upload_success_.$file_name_temp.'';
1413 }
1414
1415 }
1416 else
1417 {
1418 if ($function!=null)
1419 {
1420 call_user_func($function,_upload_failed_);
1421 }
1422 else
1423 {
1424 return _upload_failed_;
1425 }
1426 }
1427 }
1428 }
1429 }
1430 else
1431 {
1432 $size_maxium =round(self::$maximum_size / 1000);
1433 if ($function!=null)
1434 {
1435 call_user_func($function,_upload_max_.$size_maxium." KB");
1436 }
1437 else
1438 {
1439 return _upload_max_.$size_maxium." KB";
1440 }
1441 }
1442 }
1443 else
1444 {
1445 if ($function!=null)
1446 {
1447
1448 call_user_func($function,_upload_exist_.$file_name_temp);
1449 }
1450 else
1451 {
1452 return _upload_exist_.$file_name_temp;
1453 }
1454 }
1455 }
1456 }
1457 }
1458
1459class prettyPost
1460{
1461 private $post,$first_line,$count_line; private $data = array(); function __construct($str='') {$p = new HTML_Generator($str); $text = $p->getText(); if ($this->checkLastHastag($text)) {$str= rtrim($str,"#"); } $this->post = (trim($str)); $this->countHastag(); if ($this->count_line>0) {$this->setFirstLine(); if ($this->parsePost()==false) {$gf = new GF_Message(); $gf->showError("MaxPost",$str); } } else {$this->data = array($str); } } private function checkLastHastag($str) {if (empty($str)) {return false; } else {$check_last_line = $str[strlen($str) - 1]; return $check_last_line =='#' ? true : false; } } public function setFirstLine() {$result_first_line = explode('#',$this->post); $this->first_line = $result_first_line[0]; } public function getFirstLine(){return $this->first_line; } private function countHastag() {$this->count_line =substr_count($this->post, '#'); return $this->count_line; } public function parsePost() {$result_uri = explode('#',$this->post); $count_uri = count($result_uri); if ($this->count_line==0) {return false; } else if ($this->count_line==1) {$this->data = array($result_uri[0],$result_uri[1]); return true; } else if ($this->count_line==2) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2]); return true; } else if ($this->count_line==3) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3]); return true; } else if ($this->count_line==4) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4]); return true; } else if ($this->count_line==5) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5]); return true; } else if ($this->count_line==6) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6]); return true; } else if ($this->count_line==7) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7]); return true; } else if ($this->count_line==8) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7],$result_uri[8]); return true; } else if ($this->count_line==9) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7],$result_uri[8],$result_uri[9]); return true; } else if ($this->count_line==10) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7],$result_uri[8],$result_uri[9],$result_uri[10]); return true; } else if ($this->count_line==11) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7],$result_uri[8],$result_uri[9],$result_uri[10],$result_uri[11]); return true; } else if ($this->count_line==12) {$this->data = array($result_uri[0],$result_uri[1],$result_uri[2],$result_uri[3] ,$result_uri[4],$result_uri[5],$result_uri[6],$result_uri[7],$result_uri[8],$result_uri[9],$result_uri[10],$result_uri[11],$result_uri[12]); return true; } else {return false; } }
1462
1463
1464 public function getData()
1465 {
1466 return array_map('trim', $this->data);
1467 }
1468
1469}
1470
1471
1472class GF_Post
1473{
1474 private static $request_post = array();
1475
1476 public static function everythingPost()
1477 {
1478 return (isset($_POST)) ? self::$request_post = array_map('trim', $_POST) : false;
1479 }
1480
1481 public static function clean($key=null)
1482 {
1483 if ($key != null)
1484 {
1485 unset($_POST[$key]);
1486 return true;
1487 }
1488 else
1489 {
1490 unset($_POST);
1491 return false;
1492 }
1493 }
1494
1495 public static function post($str)
1496 {
1497 $result_hastag = substr_count($str, '#');
1498 if ( $result_hastag > 0 )
1499 {
1500 $p = new prettyPost($str);
1501 $data = $p->getData();
1502 $count_post = count($data);
1503 for ($i=0; $i < $count_post; $i++)
1504 {
1505 if (isset($_POST[$data[$i]]) && _requestMethod())
1506 {
1507 if (! empty(trim($_POST[$data[$i]])))
1508 {
1509 self::$request_post[$data[$i]] = ($_POST[$data[$i]]);
1510 }
1511 else
1512 {
1513 self::$request_post[$data[$i]] = false ;
1514 }
1515 }
1516 else
1517 {
1518 self::$request_post[$data[$i]] = false ;
1519 }
1520 }
1521 }
1522 else if ($result_hastag == 1)
1523 {
1524 return true;
1525 if (isset($_POST[$data[$str]]))
1526 {
1527 self::$request_post[$data[$str]] = $_POST[$str];
1528 }
1529 }
1530 }
1531
1532 public static function getPost($key)
1533 {
1534 $r = array_search($key, self::$request_post);
1535 return $r ? $r : false;
1536 }
1537 public static function getAll()
1538 {
1539 return (count(self::$request_post)>0) ? self::$request_post : false;
1540 }
1541
1542 public static function check()
1543 {
1544 if (array_search(false,self::$request_post)) {return false; } else {return true; }
1545 }
1546
1547}
1548class GF_Encode_Decode
1549{
1550
1551 private static $get_value,$result_value_encode,$result_value_decode; private static $new_data_encode= array(),$new_data_decode = array();
1552 private static $__data_angka = array("1","2","3","4","5","6","7","8","9","0"); private static $__data_huruf = array("?","$","*","~","!","^","%",">","-","|"); public static function set($value) {self::$get_value = $value; } public static function getDecode() {$length_old = self::length(); for ($i=0; $i < $length_old ; $i++) {$result = substr(self::$get_value,$i, 1); self::$new_data_decode[$i] = self::decodeInt($result); } $length = count(self::$new_data_decode); for($x=0;$x<$length;$x++) {self::$result_value_decode.= self::$new_data_decode[$x]; } return self::$result_value_decode; } public static function getEncode() {$length_old = self::length(); for ($i=0; $i < $length_old ; $i++) {$result = substr(self::$get_value,$i, 1); self::$new_data_encode[$i] = self::encodeInt($result); } $length = count(self::$new_data_encode); for($x=0;$x<$length;$x++) {self::$result_value_encode.= self::$new_data_encode[$x]; } return self::$result_value_encode; } private static function decodeInt($_val) {if ($_val==self::$__data_huruf[2]) {return self::$__data_angka[9]; } if ($_val==self::$__data_huruf[4]) {return self::$__data_angka[7]; } if ($_val==self::$__data_huruf[6]) {return self::$__data_angka[5]; } if ($_val==self::$__data_huruf[8]) {return self::$__data_angka[3]; } if ($_val==self::$__data_huruf[1]) {return self::$__data_angka[0]; } if ($_val==self::$__data_huruf[3]) {return self::$__data_angka[1]; } if ($_val==self::$__data_huruf[5]) {return self::$__data_angka[2]; } if ($_val==self::$__data_huruf[7]) {return self::$__data_angka[4]; } if ($_val==self::$__data_huruf[9]) {return self::$__data_angka[6]; } if ($_val==self::$__data_huruf[0]) {return self::$__data_angka[8]; } else {return strtoupper($_val); } } private static function encodeInt($_val) {if ($_val==self::$__data_angka[9]) {return self::$__data_huruf[2]; } if ($_val==self::$__data_angka[7]) {return self::$__data_huruf[4]; } if ($_val==self::$__data_angka[5]) {return self::$__data_huruf[6]; } if ($_val==self::$__data_angka[3]) {return self::$__data_huruf[8]; } if ($_val==self::$__data_angka[0]) {return self::$__data_huruf[1]; } if ($_val==self::$__data_angka[1]) {return self::$__data_huruf[3]; } if ($_val==self::$__data_angka[2]) {return self::$__data_huruf[5]; } if ($_val==self::$__data_angka[4]) {return self::$__data_huruf[7]; } if ($_val==self::$__data_angka[6]) {return self::$__data_huruf[9]; } if ($_val==self::$__data_angka[8]) {return self::$__data_huruf[0]; } } private static function length() {return strlen(self::$get_value); }
1553}
1554
1555
1556class GF_Encrypt_Decrypt
1557{
1558 private $secret_key = 'SECRETKEY',$secret_iv = 'SECRETIV';
1559 private $encrypt_method = 'AES-256-CBC',$hash_type ='sha384';
1560 private $value;
1561
1562 private $key,$iv;
1563
1564 private $allHash = array( 'md2', 'md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'ripemd256', 'ripemd320', 'whirlpool', 'tiger128,3', 'tiger160,3', 'tiger192,3', 'tiger128,4', 'tiger160,4', 'tiger192,4', 'snefru', 'gost', 'adler32', 'crc32', 'crc32b', 'haval128,3', 'haval160,3', 'haval192,3', 'haval224,3', 'haval256,3', 'haval128,4', 'haval160,4', 'haval192,4', 'haval224,4', 'haval256,4', 'haval128,5', 'haval160,5', 'haval192,5', 'haval224,5', 'haval256,5'
1565 );
1566
1567 public function getAllHash(){
1568 return $this->allHash;
1569 }
1570
1571 public function setKey($v){
1572 $this->secret_key = $v;
1573 }
1574
1575 public function setValue($v){
1576 $this->value = $v;
1577 }
1578
1579 public function setHasType($v){
1580 $this->hash_type = $v;
1581 }
1582
1583 public function getHashType(){
1584 return $this->hash_type;
1585 }
1586
1587 public function setIv($v){
1588 $this->secret_iv;
1589 }
1590
1591 public function setEncryptMethod($v){
1592 $this->encrypt_method = $v;
1593 }
1594
1595 public function encrypt(){
1596 $this->calculate();
1597 return base64_encode(openssl_encrypt($this->value, $this->encrypt_method, $this->key, 0, $this->iv));
1598 }
1599
1600 private function calculate(){
1601 $this->key = hash($this->hash_type, $this->secret_key);
1602 $this->iv = substr(hash($this->hash_type, $this->secret_iv), 0, 16);
1603 }
1604
1605 public function decrypt(){
1606 $this->calculate();
1607 return openssl_decrypt(base64_decode($this->value), $this->encrypt_method, $this->key, 0, $this->iv);
1608 }
1609}