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
|
|
|
// FIXME 'netjes' een path opzoeken hier voor |
|
|
|
|
26
|
|
|
$cachepath = sha1($path . $name); |
27
|
|
|
$cacheroot = '/home/muller/devel/site/files/temp/'; |
28
|
|
|
if ( |
29
|
|
|
! file_exists( $cacheroot . $cachepath ) || |
30
|
|
|
( filemtime($cacheroot . $cachepath ) < filemtime ( $realpath . $name ) ) |
31
|
|
|
) { |
32
|
|
|
$compiled = $this->compile($path, $name); |
33
|
|
|
file_put_contents($cacheroot . $cachepath, $compiled); |
34
|
|
|
} |
35
|
|
|
include ( $cacheroot . $cachepath ); |
36
|
|
|
return $arTemplateFunction; |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function save($path, $name, $template, $local=null, $private=null) { |
|
|
|
|
40
|
|
|
return false; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function load($path, $name) { |
|
|
|
|
44
|
|
|
$arpath = path::collapse($path); |
45
|
|
|
|
46
|
|
|
if ( strpos($arpath, $this->path, 0) !== 0) { |
47
|
|
|
return ar('error')->raiseError('invalide path for loading template',500); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$realpath = $this->config['path'] . substr($arpath,strlen($this->path)); |
51
|
|
|
$realpath = realpath($realpath) .'/'; |
52
|
|
|
|
53
|
|
|
return file_get_contents($realpath . $name); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function ls($path) { |
57
|
|
|
$arpath = path::collapse($path); |
58
|
|
|
|
59
|
|
|
if ( strpos($arpath, $this->path, 0) !== 0) { |
60
|
|
|
return []; |
61
|
|
|
} |
62
|
|
|
$realpath = $this->config['path'] . substr($arpath,strlen($this->path)); |
63
|
|
|
$realpath = realpath($realpath) .'/'; |
64
|
|
|
$config = json_decode(file_get_contents($realpath . 'library.json'),true); |
65
|
|
|
if(!isset($config['exports']) ) { |
66
|
|
|
$config['exports'] = []; |
67
|
|
|
} |
68
|
|
|
if(!isset($config['local']) ) { |
69
|
|
|
$config['local'] = []; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$result = []; |
73
|
|
|
|
74
|
|
|
$traverseDir = function ($path, $type = 'pobject', $nls = 'any') use ($arpath, &$result, $config, &$traverseDir, $realpath) { |
75
|
|
|
$path = path::collapse($path); |
76
|
|
|
$index = scandir($path, SCANDIR_SORT_NONE); |
77
|
|
|
if($index !== false) { |
78
|
|
|
list($maintype, $subtype) = explode('.', $type,2); |
79
|
|
|
foreach($index as $filename) { |
80
|
|
|
if($filename[0] === "." ) { |
81
|
|
|
continue; |
82
|
|
|
} |
83
|
|
|
$filepath = $path . $filename; |
84
|
|
|
if ( is_dir($filepath) ) { |
85
|
|
|
if (strlen($filename) == 2) { |
86
|
|
|
$traverseDir(path::collapse($filename, $path), $type, $filename); |
87
|
|
|
} else { |
88
|
|
|
$traverseDir(path::collapse($filename, $path), $filename); |
89
|
|
|
} |
90
|
|
|
} else if ( is_file($filepath) ) { |
91
|
|
|
$tempname = sprintf("%s.%s.%s",$type,$filename,$nls); |
92
|
|
|
$confname = sprintf("%s::%s",$type,$filename); |
93
|
|
|
$private = true; |
94
|
|
|
if (isset( $config['exports'] ) ) { |
95
|
|
|
$private = ! in_array($confname, $config['exports']); |
96
|
|
|
} |
97
|
|
|
$local = false; |
98
|
|
|
if (isset( $config['local'] ) ) { |
99
|
|
|
$local = in_array($confname, $config['local']); |
100
|
|
|
} |
101
|
|
|
$result[$filename][] = [ |
102
|
|
|
'id' => PHP_INT_MAX, |
103
|
|
|
'path' => $arpath, |
104
|
|
|
'type' => $maintype, |
105
|
|
|
'subtype' => $subtype, |
106
|
|
|
'name' => $tempname, |
107
|
|
|
'filename' => substr($filepath,strlen($realpath)), |
108
|
|
|
'language' => $nls, |
109
|
|
|
'private' => $private, |
110
|
|
|
'local' => $local, |
111
|
|
|
]; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
}; |
117
|
|
|
$traverseDir($realpath . 'src/'); |
118
|
|
|
return $result; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function rm($path, $name){ |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
View Code Duplication |
public function exists($path, $name) { |
|
|
|
|
125
|
|
|
$arpath = path::collapse($path); |
126
|
|
|
|
127
|
|
|
if ( strpos($arpath, $this->path, 0) !== 0) { |
128
|
|
|
return ar('error')->raiseError('invalide path for loading template',500); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$realpath = $this->config['path'] . substr($arpath,strlen($this->path)); |
132
|
|
|
$realpath = realpath($realpath) .'/'; |
133
|
|
|
return file_exists($realpath . $name); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function compile($path, $name) { |
137
|
|
|
global $AR; |
138
|
|
|
$arpath = path::collapse($path); |
139
|
|
|
|
140
|
|
|
if ( strpos($arpath, $this->path, 0) !== 0) { |
141
|
|
|
return ar('error')->raiseError('invalide path for loading template',500); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
$realpath = $this->config['path'] . substr($arpath,strlen($this->path)); |
145
|
|
|
$realpath = realpath($realpath) .'/'; |
146
|
|
|
|
147
|
|
|
$template = file_get_contents($realpath . $name); |
148
|
|
|
|
149
|
|
|
require_once(AriadneBasePath."/modules/mod_pinp.phtml"); |
150
|
|
|
|
151
|
|
|
$pinp = new pinp($AR->PINP_Functions, "local->", "\$AR_this->_"); |
152
|
|
|
|
153
|
|
|
// FIXME error checking |
|
|
|
|
154
|
|
|
$compiled = $pinp->compile(strtr($template,"\r","")); |
155
|
|
|
$compiled = sprintf($AR->PINPtemplate, $compiled); |
156
|
|
|
return $compiled; |
157
|
|
|
|
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|