/
css.php
136 lines (112 loc) · 3.29 KB
/
css.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
// p2 - スタイルシートを外部スタイルシートとして出力する
/*
<link rel="stylesheet" type="text/css" href="css.php?css=style&user=nanashi&skin=">
<link rel="stylesheet" type="text/css" href="css.php?css=read&user=nanashi&skin=">
*/
require_once './conf/conf.inc.php' ;
//$_login->authorize(); // ユーザ認証
// 妥当なCSSファイル指定か検証して取得する
if (!isset($_GET['css']) or !$cssFilePath = _getValidCssFilePath($_GET['css'])) {
exit;
}
// CSS出力
_printCss($cssFilePath, geti($_GET['skin']));
exit;
//===============================================================================
// 関数(このファイル内でのみ利用)
//===============================================================================
/**
* @return void CSS出力
*/
function _printCss($cssFilePath, $skin = null)
{
global $_conf, $STYLE, $MYSTYLE;
/*
// クエリにユニークキーを埋め込んでいるいるので、キャッシュさせてよい
// ノーマルp2ではまだ含んでないよ
$now = time();
header('Expires: ' . http_date($now + 3600));
header('Last-Modified: ' . http_date($now));
header('Pragma: cache');
header('Content-Type: text/css; charset=Shift_JIS');
*/
$mtime = max(filemtime($cssFilePath), filemtime(_getSkinFilePath($skin)));
if (file_exists($_conf['conf_user_file'])) {
$mtime = max($mtime, filemtime($_conf['conf_user_file']));
}
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $mtime) . ' GMT');
header('Content-Type: text/css; charset=Shift_JIS');
echo "@charset \"Shift_JIS\";\n\n";
ob_start();
include_once $cssFilePath; // $STYLEを含む
// $MYSTYLEでCSSを上書き表示
require_once P2_LIB_DIR . '/mystyle_css.funcs.php';
$MYSTYLE = parse_mystyle($MYSTYLE);
printMystyleCssByFileName($cssFilePath);
// 空スタイルを除去
echo preg_replace('/[a-z\\-]+[ \\t]*:[ \\t]*;/', '', ob_get_clean());
}
/**
* @return string
*/
function _getCssFilePath($cssName)
{
return P2_STYLE_DIR . DIRECTORY_SEPARATOR . rawurlencode($cssName) . '_css.inc';
}
/**
* 妥当なCSSファイル指定か検証して取得する
*
* @return string|false
*/
function _getValidCssFilePath($cssName)
{
if (preg_match('/^\\w+$/', $cssName)) {
$cssFilePath = _getCssFilePath($cssName);
if (file_exists($cssFilePath)) {
return $cssFilePath;
}
}
return false;
}
/**
* @return string
*/
function _getSkinFilePath($skin = null)
{
global $_conf;
$skinFilePath = '';
if ($skin) {
$skinFilePath = P2Util::getSkinFilePathBySkinName($skin);
} elseif ($skin_setting_path = _getSkinSettingPath()) {
$skinFilePath = P2Util::getSkinFilePathBySkinName($skin_setting_path);
}
if (!$skinFilePath || !is_file($skinFilePath)) {
$skinFilePath = $_conf['conf_user_style_inc_php'];
}
return $skinFilePath;
}
/**
* @return string|null|false
*/
function _getSkinSettingPath()
{
global $_conf;
if (file_exists($_conf['skin_setting_path'])) {
if (false === $cont = file_get_contents($_conf['skin_setting_path'])) {
return false;
}
return rtrim($cont);
}
return null;
}
/*
* Local Variables:
* mode: php
* coding: cp932
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker: