forked from zerotri/blurcms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathless.php
69 lines (65 loc) · 1.98 KB
/
less.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
<?php
/**
* Code modified by Wynter Woods for Windowpane.
* Uses a LessPHP rather than the original Ruby LESS.
* This allows less files to be compiled on the fly by
* any server supporting PHP, and removes the Ruby
* requirement.
*
* There is a caveat to this, which is documented at
* the LessPHP site: http://leafo.net/lessphp/docs/
**/
/**
* LESS PHP cacher [http://github.com/aaronrussell/less_php_cacher]
* Extension to LESS for creating cached stylesheets your PHP projects can use
* Copyright (c) 2009 Aaron Russell [http://www.aaronrussell.co.uk]
* Licensed under the MIT license [http://www.opensource.org/licenses/mit-license.php]
* Less is maintained by Alexis Sellier [http://github.com/cloudhead/less]
*
* Preparation: lessphpc [command]
* Commands:
* prepare Installs the PHP wrapper for LESS and creates a cache folder in your web root
* remove Removes the PHP wrapper from your web project
* update Updates the PHP wrapper to the latest version
* help Displays this help dialogue
*
* Integration:
* <link rel="stylesheet" href="less.php?stylesheet.less" type="text/css">
* ..or..
* <?php include 'less.php'; ?>
* <style type="text/css">
* <?php less_php('stylesheet.less'); ?>
* </style>
**/
require_once ('globals.php');
require_once ( ROOT . '/library/lessc.inc.php' );
define ('NL', "\n");
function less_php($less){
$source = preg_replace('/(\.less|_less)\Z/i', '', $less);
$cache = ROOT.'/tmp/cache/'.$source.'.css';
$sourcefile = ROOT."/".$source . ".less";
if(file_exists($cache) && filemtime($cache) >= filemtime($sourcefile))
{
$f = fopen($cache, 'r');
echo fread($f, filesize($cache));
fclose($f);
}
else
{
$less = new lessc($sourcefile);
$data = $less->parse();
$f = fopen($cache, 'w');
fputs($f, $data);
fclose($f);
echo $data;
}
}
if ($_GET):
$args = array();
foreach ($_GET as $key => $value):
array_push($args, $key);
endforeach;
Header("Content-type: text/css");
less_php($args[0]);
endif;
?>