1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use arc\path as path; |
4
|
|
|
|
5
|
|
|
class ar_template_filesystem extends arBase { |
6
|
|
|
private $path; |
7
|
|
|
private $config; |
8
|
|
|
|
9
|
|
|
public function __construct($path, $config ) { |
10
|
|
|
$this->path = path::collapse($path); |
11
|
|
|
$this->config = $config; |
12
|
|
|
$this->config['path'] = path::collapse($config['path']); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function get($path, $name){ |
16
|
|
|
$arpath = path::collapse($path); |
17
|
|
|
|
18
|
|
|
if ( strpos($arpath, $this->path, 0) !== 0) { |
19
|
|
|
return ar('error')->raiseError('invalide path for loading template',500); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
$realpath = $this->config['path'] . substr($arpath,strlen($this->path)); |
23
|
|
|
$realpath = realpath($realpath) .'/'; |
24
|
|
|
|
25
|
|
|
$cachepath = sha1($path . $name); |
26
|
|
|
$tempOb = ar::context()->getObject(); |
27
|
|
|
$cacheroot = $tempOb->store->get_config('files').'temp/'; |
28
|
|
|
|
29
|
|
|
if ( |
30
|
|
|
! file_exists( $cacheroot . $cachepath ) || |
31
|
|
|
( filemtime($cacheroot . $cachepath ) < filemtime ( $realpath . $name ) ) |
32
|
|
|
) { |
33
|
|
|
$compiled = $this->compile($path, $name); |
34
|
|
|
file_put_contents($cacheroot . $cachepath, $compiled); |
35
|
|
|
} |
36
|
|
|
include ( $cacheroot . $cachepath ); |
37
|
|
|
return $arTemplateFunction; |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function save($path, $name, $template, $local=null, $private=null) { |
|
|
|
|
41
|
|
|
return false; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function load($path, $name) { |
|
|
|
|
45
|
|
|
$arpath = path::collapse($path); |
46
|
|
|
|
47
|
|
|
if ( strpos($arpath, $this->path, 0) !== 0) { |
48
|
|
|
return ar('error')->raiseError('invalide path for loading template',500); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$realpath = $this->config['path'] . substr($arpath,strlen($this->path)); |
52
|
|
|
$realpath = realpath($realpath) .'/'; |
53
|
|
|
|
54
|
|
|
return file_get_contents($realpath . $name); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function ls($path) { |
58
|
|
|
$arpath = path::collapse($path); |
59
|
|
|
|
60
|
|
|
if ( strpos($arpath, $this->path, 0) !== 0) { |
61
|
|
|
return []; |
62
|
|
|
} |
63
|
|
|
$realpath = $this->config['path'] . substr($arpath,strlen($this->path)); |
64
|
|
|
$realpath = realpath($realpath) .'/'; |
65
|
|
|
$traverse = 'src/'; |
66
|
|
|
if (!file_exists($realpath . 'library.json')) { |
67
|
|
|
$realparent = path::parent($realpath); |
68
|
|
|
$node = basename($realpath); |
69
|
|
|
if ($node === 'tests' && file_exists($realparent . 'library.json') ) { |
70
|
|
|
// special case |
71
|
|
|
// system/lib/libname/tests/ is a sibling of src instead of a child library |
72
|
|
|
$traverse = 'tests/'; |
73
|
|
|
$arpath = path::parent($path); |
74
|
|
|
$realpath = $realparent; |
75
|
|
|
} else { |
76
|
|
|
return []; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$config = json_decode(file_get_contents($realpath . 'library.json'),true); |
81
|
|
|
|
82
|
|
|
if(!isset($config['exports']) ) { |
83
|
|
|
$config['exports'] = []; |
84
|
|
|
} |
85
|
|
|
if(!isset($config['local']) ) { |
86
|
|
|
$config['local'] = []; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$result = []; |
90
|
|
|
|
91
|
|
|
$traverseDir = function ($path, $type = 'pobject', $nls = 'any') use ($arpath, &$result, $config, &$traverseDir, $realpath) { |
92
|
|
|
$path = path::collapse($path); |
93
|
|
|
if (is_dir($path) ) { |
94
|
|
|
$index = scandir($path, SCANDIR_SORT_NONE); |
95
|
|
|
if($index !== false) { |
96
|
|
|
list($maintype, $subtype) = explode('.', $type,2); |
97
|
|
|
foreach($index as $filename) { |
98
|
|
|
if($filename[0] === "." ) { |
99
|
|
|
continue; |
100
|
|
|
} |
101
|
|
|
$filepath = $path . $filename; |
102
|
|
|
if ( is_dir($filepath) ) { |
103
|
|
|
if (strlen($filename) == 2) { |
104
|
|
|
$traverseDir(path::collapse($filename, $path), $type, $filename); |
105
|
|
|
} else { |
106
|
|
|
$traverseDir(path::collapse($filename, $path), $filename); |
107
|
|
|
} |
108
|
|
|
} else if ( is_file($filepath) ) { |
109
|
|
|
$tempname = sprintf("%s.%s.%s",$type,$filename,$nls); |
110
|
|
|
$confname = sprintf("%s::%s",$type,$filename); |
111
|
|
|
$private = true; |
112
|
|
|
if (isset( $config['exports'] ) ) { |
113
|
|
|
$private = ! in_array($confname, $config['exports']); |
114
|
|
|
} |
115
|
|
|
$local = false; |
116
|
|
|
if (isset( $config['local'] ) ) { |
117
|
|
|
$local = in_array($confname, $config['local']); |
118
|
|
|
} |
119
|
|
|
$result[$filename][] = [ |
120
|
|
|
'id' => PHP_INT_MAX, |
121
|
|
|
'path' => $arpath, |
122
|
|
|
'type' => $maintype, |
123
|
|
|
'subtype' => $subtype, |
124
|
|
|
'name' => $tempname, |
125
|
|
|
'filename' => substr($filepath,strlen($realpath)), |
126
|
|
|
'language' => $nls, |
127
|
|
|
'private' => $private, |
128
|
|
|
'local' => $local, |
129
|
|
|
]; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
}; |
136
|
|
|
$traverseDir($realpath . $traverse ); |
137
|
|
|
return $result; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function rm($path, $name){ |
|
|
|
|
141
|
|
|
} |
142
|
|
|
|
143
|
|
View Code Duplication |
public function exists($path, $name) { |
|
|
|
|
144
|
|
|
$arpath = path::collapse($path); |
145
|
|
|
|
146
|
|
|
if ( strpos($arpath, $this->path, 0) !== 0) { |
147
|
|
|
return ar('error')->raiseError('invalide path for loading template',500); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
$realpath = $this->config['path'] . substr($arpath,strlen($this->path)); |
151
|
|
|
$realpath = realpath($realpath) .'/'; |
152
|
|
|
return file_exists($realpath . $name); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function compile($path, $name) { |
156
|
|
|
global $AR; |
157
|
|
|
$arpath = path::collapse($path); |
158
|
|
|
|
159
|
|
|
if ( strpos($arpath, $this->path, 0) !== 0) { |
160
|
|
|
return ar('error')->raiseError('invalide path for loading template',500); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
$realpath = $this->config['path'] . substr($arpath,strlen($this->path)); |
164
|
|
|
$realpath = realpath($realpath) .'/'; |
165
|
|
|
|
166
|
|
|
$template = file_get_contents($realpath . $name); |
167
|
|
|
|
168
|
|
|
require_once(AriadneBasePath."/modules/mod_pinp.phtml"); |
169
|
|
|
|
170
|
|
|
$pinp = new pinp($AR->PINP_Functions, "local->", "\$AR_this->_"); |
171
|
|
|
|
172
|
|
|
// FIXME error checking |
|
|
|
|
173
|
|
|
$compiled = $pinp->compile(strtr($template,"\r","")); |
174
|
|
|
$compiled = sprintf($AR->PINPtemplate, $compiled); |
175
|
|
|
return $compiled; |
176
|
|
|
|
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.