-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_helper.php
58 lines (47 loc) · 904 Bytes
/
common_helper.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
<?php
function DEVPREFIX(){
if($_SERVER['SERVER_NAME'] == "localhost"){
return "dev";
}else{
return "";
}
}
function get_ujdonsag(){
return JS_READER(getDataPath()."ujdonsag.json");
}
function save_ujdonsag($ujdonsag){
return JS_WRITER(getDataPath()."ujdonsag.json",$ujdonsag);
}
function getDataPath(){
global $NOTADMIN;
if(isset($NOTADMIN)){
$path = "admin/data/".DEVPREFIX();
}else{
$path = "data/".DEVPREFIX();
}
return $path;
}
function JS_READER($path){
$jsonstr = "";
if(file_exists($path)){
if ($file = fopen($path, "r")) {
while(!feof($file)) {
$line = fgets($file);
$jsonstr .= $line."\n";
}
fclose($file);
}else{
return null;
}
}else{
return null;
}
$json = json_decode($jsonstr,3);
return $json;
}
function JS_WRITER($path,$json){
$myfile = fopen($path, "w");
fwrite($myfile, json_encode($json));
return fclose($myfile);
}
?>