-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathedit_user_font.php
More file actions
281 lines (249 loc) · 10.2 KB
/
edit_user_font.php
File metadata and controls
281 lines (249 loc) · 10.2 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
/**
* rep2expack - フォント設定編集インタフェース
*/
// {{{ 初期化
// 初期設定読み込み & ユーザ認証
require_once './conf/conf.inc.php';
$_login->authorize();
require_once P2_LIB_DIR . '/fontconfig.inc.php';
require_once 'HTML/Template/Flexy.php';
$flexy_options = array(
'templateDir' => './skin',
'compileDir' => $_conf['compile_dir'] . DIRECTORY_SEPARATOR . 'fontconfig',
'locale' => 'ja',
'charset' => 'cp932',
);
$fontconfig_types = array(
'windows' => 'Windows',
'safari3' => 'Safari3',
'safari2' => 'Safari2',
'safari1' => 'Safari1',
'macosx' => 'Mac OS X (Safari以外)',
'macos9' => 'Mac OS classic',
// 'pda' => 'PDA, 携帯フルブラウザ', // 情報不足のため判定ルーチンが書けない
'other' => 'その他',
);
$fontconfig_params = array('fontfamily', 'fontfamily_bold', 'fontweight_bold', 'fontstyle_bold', 'fontfamily_aa', 'fontsize', 'menu_fontsize', 'sb_fontsize', 'read_fontsize', 'respop_fontsize', 'infowin_fontsize', 'form_fontsize');
$fontconfig_weights = array('normal', 'bold', 'lighter', 'bolder'/*, '100', '200', '300', '400', '500', '600', '700', '800', '900'*/);
$fontconfig_styles = array('normal', 'italic', 'oblique');
$fontconfig_sizes = array('6px', '8px', '9px', '10px', '11px', '12px', '13px', '14px', '16px', '18px', '21px', '24px');
$controllerObject = (object)array(
'fontconfig_types' => $fontconfig_types,
'fontconfig_params' => $fontconfig_params,
'skindata' => p2_fontconfig_load_skin_setting(),
'safari' => 0,
'mac' => false,
);
if (file_exists($_conf['expack.skin.fontconfig_path'])) {
$current_fontconfig = unserialize(file_get_contents($_conf['expack.skin.fontconfig_path']));
if (!is_array($current_fontconfig)) {
$current_fontconfig = array('enabled' => false, 'custom' => array());
}
} else {
FileCtl::make_datafile($_conf['expack.skin.fontconfig_path'], $_conf['expack.skin.fontconfig_perm']);
$current_fontconfig = array('enabled' => false, 'custom' => array());
}
$fontconfig_hash = md5(serialize($current_fontconfig));
$updated_fontconfig = array('enabled' => false, 'custom' => array());
// Mac はブラウザによって文字のレンダリング結果が大きく変わり
// その種類もそこそこ多いので現在のブラウザにマッチしないものを隠す
$ft = &$controllerObject->fontconfig_types;
$type = p2_fontconfig_detect_agent();
switch ($type) {
case 'safari3':
$controllerObject->safari = 3;
unset($ft['safari2'], $ft['safari1'], $ft['macosx'], $ft['macos9']);
break;
case 'safari2':
$controllerObject->safari = 2;
unset($ft['safari3'], $ft['safari1'], $ft['macosx'], $ft['macos9']);
break;
case 'safari1':
$controllerObject->safari = 1;
unset($ft['safari3'], $ft['safari2'], $ft['macosx'], $ft['macos9']);
break;
case 'macosx':
$controllerObject->mac = true;
unset($ft['safari2'], $ft['safari1'], $ft['macos9']);
break;
case 'macos9':
$controllerObject->mac = true;
unset($ft['safari3'], $ft['safari2'], $ft['safari1'], $ft['macosx']);
break;
default:
unset($ft['safari2'], $ft['safari1'], $ft['macosx'], $ft['macos9']);
}
// }}}
if (!is_dir($_conf['compile_dir'])) {
FileCtl::mkdirRecursive($_conf['compile_dir']);
}
// テンプレートをコンパイル
$flexy = new HTML_Template_Flexy($flexy_options);
$flexy->compile('edit_user_font.tpl.html');
$elements = $flexy->getElements();
// カスタム設定を利用するか否かを切り替える
if (isset($_POST['use_skin'])) {
$use_skin = is_array($_POST['use_skin']) ? current($_POST['use_skin']) : $_POST['use_skin'];
} else {
$use_skin = !$current_fontconfig['enabled'];
}
if ($use_skin) {
$elements['use_skin']->setAttributes(array('checked' => true));
$elements['use_user']->setAttributes(array('checked' => false));
$updated_fontconfig['enabled'] = false;
} else {
$elements['use_skin']->setAttributes(array('checked' => false));
$elements['use_user']->setAttributes(array('checked' => true));
$updated_fontconfig['enabled'] = true;
}
// 変更の適用と、フォームへ値を代入
if (!empty($_POST['clear'])) {
$_POST = array();
$current_fontconfig['custom'] = array();
}
foreach ($fontconfig_params as $pname) {
$elemName = $pname . '[%s]';
if (isset($elements[$elemName])) {
foreach ($fontconfig_types as $tname => $ttitle) {
$newElemName = sprintf($elemName, $tname);
if (!isset($elements[$newElemName])) {
$elements[$newElemName] = clone $elements[$elemName];
}
if (!array_key_exists($tname, $updated_fontconfig['custom']) ||
!is_array($updated_fontconfig['custom'][$tname]))
{
$updated_fontconfig['custom'][$tname] = array();
}
if (isset($_POST[$pname][$tname])) {
$value = trim($_POST[$pname][$tname]);
} elseif (isset($current_fontconfig['custom'][$tname][$pname])) {
$value = $current_fontconfig['custom'][$tname][$pname];
} else {
$value = '';
}
if ($elements[$newElemName]->tag == 'select') {
if (strpos($pname, 'fontweight') !== false) {
$option_values = $fontconfig_weights;
$option_labels = $fontconfig_weights;
array_unshift($option_values, '');
array_unshift($option_labels, 'inherit');
$elements[$newElemName]->setOptions(array_combine($option_values, $option_labels));
if ($value !== '' && !in_array($value, $fontconfig_weights)) {
$elements[$newElemName]->setOptions(array($value, $value));
}
} else if (strpos($pname, 'fontstyle') !== false) {
$option_values = $fontconfig_styles;
$option_labels = $fontconfig_styles;
array_unshift($option_values, '');
array_unshift($option_labels, 'inherit');
$elements[$newElemName]->setOptions(array_combine($option_values, $option_labels));
if ($value !== '' && !in_array($value, $fontconfig_styles)) {
$elements[$newElemName]->setOptions(array($value, $value));
}
} else if (strpos($pname, 'fontsize') !== false) {
$option_values = $fontconfig_sizes;
$option_labels = $fontconfig_sizes;
array_unshift($option_values, '');
array_unshift($option_labels, 'inherit');
$elements[$newElemName]->setOptions(array_combine($option_values, $option_labels));
if ($value !== '' && !in_array($value, $fontconfig_sizes)) {
$elements[$newElemName]->setOptions(array($value, $value));
}
}
}
if ($value) {
$updated_fontconfig['custom'][$tname][$pname] = $value;
}
$elements[$newElemName]->setValue($value);
}
}
}
// 保存
$fontconfig_data = serialize($updated_fontconfig);
$fontconfig_new_hath = md5($fontconfig_data);
if (strcmp($fontconfig_hash, $fontconfig_new_hath) != 0) {
FileCtl::file_write_contents($_conf['expack.skin.fontconfig_path'], $fontconfig_data);
chmod($_conf['expack.skin.fontconfig_path'], $_conf['p2_perm']);
}
// スタイルシートをリセット
unset($STYLE);
include $skin;
foreach ($STYLE as $K => $V) {
if (empty($V)) {
$STYLE[$K] = '';
} elseif (strpos($K, 'fontfamily') !== false) {
$STYLE[$K] = p2_correct_css_fontfamily($V);
} elseif (strpos($K, 'color') !== false) {
$STYLE[$K] = p2_correct_css_color($V);
} elseif (strpos($K, 'background') !== false) {
$STYLE[$K] = 'url("' . addslashes($V) . '")';
}
}
if ($updated_fontconfig['enabled']) {
p2_fontconfig_apply_custom();
} else {
$skin_en = preg_replace('/&_=[^&]*/', '', $skin_en) . '&_=' . rawurlencode($skin_uniq);
}
$controllerObject->STYLE = $STYLE;
$controllerObject->skin = $skin_en;
$controllerObject->p2vid = P2_VERSION_ID;
// 出力
$flexy->outputObject($controllerObject, $elements);
// {{{ p2_fontconfig_load_skin_setting()
/**
* カスタム設定で上書きされていないスキン設定を読み込む
*/
function p2_fontconfig_load_skin_setting()
{
global $_conf, $STYLE;
$skindata = array();
$fontfamily = (isset($STYLE['fontfamily.orig']))
? $STYLE['fontfamily.orig']
: ((isset($STYLE['fontfamily'])) ? $STYLE['fontfamily'] : '');
$skindata['fontfamily'] = p2_fontconfig_implode_fonts($fontfamily);
$fontfamily_bold = (isset($STYLE['fontfamily_bold.orig']))
? $STYLE['fontfamily_bold.orig']
: ((isset($STYLE['fontfamily_bold'])) ? $STYLE['fontfamily_bold'] : '');
$skindata['fontfamily_bold'] = p2_fontconfig_implode_fonts($fontfamily_bold);
$fontfamily_aa = (isset($_conf['expack.am.fontfamily.orig']))
? $_conf['expack.am.fontfamily.orig']
: ((isset($_conf['expack.am.fontfamily'])) ? $_conf['expack.am.fontfamily'] : '');
$skindata['fontfamily_aa'] = p2_fontconfig_implode_fonts($fontfamily_aa);
$normal = ($skindata['fontfamily_bold'] == '') ? '' : 'normal';
foreach (array('fontweight_bold', 'fontstyle_bold') as $key) {
$skindata[$key] = (isset($STYLE[$key])) ? (string)$STYLE[$key] : $normal;
}
foreach (array('fontsize', 'menu_fontsize', 'sb_fontsize', 'read_fontsize',
'form_fontsize', 'respop_fontsize', 'infowin_fontsize') as $key)
{
$skindata[$key] = (isset($STYLE[$key])) ? (string)$STYLE[$key] : '';
}
return $skindata;
}
// }}}
// {{{ p2_fontconfig_implode_fonts()
function p2_fontconfig_implode_fonts($fonts)
{
if (!is_array($fonts)) {
$fonts = explode(',', (string)$fonts);
}
return '"' . implode('","', array_map('p2_fontconfig_trim', $fonts)) . '"';
}
// }}}
// {{{ p2_fontconfig_trim()
function p2_fontconfig_trim($str)
{
return trim($str, " \r\n\t\x0B\"'" . P2_NULLBYTE);
}
// }}}
/*
* 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: