-
Notifications
You must be signed in to change notification settings - Fork 5
/
extension.driver.php
executable file
·89 lines (65 loc) · 2.5 KB
/
extension.driver.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
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
<?php
Class extension_SASS_Compiler extends Extension{
public function about(){
return array(
'name' => 'SASS Compiler',
'version' => '1.1',
'release-date' => '2015-07-05',
'author' => array(
array(
'name' => 'Nils Werner',
'website' => 'http://www.obssessive-media.de/',
'email' => 'nils.werner@gmail.com'
)
)
);
}
public function getSubscribedDelegates(){
return array();
}
public function install(){
General::realiseDirectory(CACHE . '/sass_compiler/', Symphony::Configuration()->get('write_mode', 'directory'));
$htaccess = @file_get_contents(DOCROOT . '/.htaccess');
if($htaccess === false) return false;
## Cannot use $1 in a preg_replace replacement string, so using a token instead
$token = md5(time());
$rule = "
### SASS RULES
RewriteRule ^sass\/(.+\.sass)\$ extensions/sass_compiler/lib/sass.php?mode=sass¶m={$token} [L,NC]
RewriteRule ^scss\/(.+\.scss)\$ extensions/sass_compiler/lib/sass.php?mode=scss¶m={$token} [L,NC]\n\n";
## Remove existing rules
$htaccess = self::__removeSassRules($htaccess);
if(preg_match('/### SASS RULES/', $htaccess)){
$htaccess = preg_replace('/### SASS RULES/', $rule, $htaccess);
}
else{
$htaccess = preg_replace('/RewriteRule .\* - \[S=14\]\s*/i', "RewriteRule .* - [S=14]\n{$rule}\t", $htaccess);
}
## Replace the token with the real value
$htaccess = str_replace($token, '$1', $htaccess);
return @file_put_contents(DOCROOT . '/.htaccess', $htaccess);
}
public function uninstall(){
$htaccess = @file_get_contents(DOCROOT . '/.htaccess');
if($htaccess === false) return false;
$htaccess = self::__removeSassRules($htaccess);
$htaccess = preg_replace('/### SASS RULES/', NULL, $htaccess);
return @file_put_contents(DOCROOT . '/.htaccess', $htaccess);
}
public function enable(){
return $this->install();
}
public function disable(){
$htaccess = @file_get_contents(DOCROOT . '/.htaccess');
if($htaccess === false) return false;
$htaccess = self::__removeSassRules($htaccess);
$htaccess = preg_replace('/### SASS RULES/', NULL, $htaccess);
return @file_put_contents(DOCROOT . '/.htaccess', $htaccess);
}
/*-------------------------------------------------------------------------
Utilities:
-------------------------------------------------------------------------*/
private static function __removeSassRules($string){
return preg_replace('/RewriteRule \^sass[^\r\n]+[\r\n]?/i', NULL, $string);
}
}