-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMeta.php
More file actions
90 lines (75 loc) · 1.51 KB
/
Meta.php
File metadata and controls
90 lines (75 loc) · 1.51 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
<?php
/**
* Meta class
*
* @package Framework
*/
require_once('API.php');
/**
* Meta
*
* System access management class.
*
* @author Marco Ceppi <[email protected]>
* @package Framework
* @subpackage Meta
*/
class Meta
{
public static $path = false;
public static function get( $user, $domain, $assoc = false )
{
if( static::$path )
{
if( empty($domain) )
{
$meta = static::$path . "/$user/*";
$metadata = array();
$meta_files = glob($meta);
foreach( $meta_files as $file )
{
$metadata[basename($file)] = json_decode(static::get_raw($file), $assoc);
}
return $metadata;
}
else
{
$meta = static::$path . "/$user/$domain";
return json_decode(static::get_raw($meta), $assoc);
}
}
}
protected static function get_raw( $path )
{
return @file_get_contents($path);
}
public static function save( $user, $domain, $data )
{
if( !is_dir(static::$path) )
{
mkdir(static::$path);
}
if( !is_dir(static::$path . "/$user") )
{
mkdir(static::$path . "/$user");
}
if( is_array($data) )
{
$meta = static::$path . "/$user/$domain";
return static::set_raw($meta, $data);
}
return false;
}
protected static function set_raw( $path, $data )
{
return (!file_put_contents($path, json_encode($data))) ? false : true;
}
public static function delete( $user, $domain )
{
return static::del_raw(static::$path . "/$user/$domain");
}
public static function del_raw( $path )
{
return @unlink($path);
}
}