-
Notifications
You must be signed in to change notification settings - Fork 0
/
MobileConverter.txt
executable file
·551 lines (496 loc) · 20.6 KB
/
MobileConverter.txt
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
//------------------------------------------------------------------------
//
// MobileConverter for MODX
//
// Author : soushi
// Version : 2.10
//
// License : GPL
//
//------------------------------------------------------------------------
//--------This plugin name
$MyName=$modx->Event->activePlugin;
$MC='MobileConverter';
// Template
$TemplateNotFound=<<<_TPLNOTFOUND_
<html>
<head>
<title>[(site_name)] | [*pagetitle*]</title>
<meta http-equiv="Content-Type" content="text/html; charset=[+charset+]" />
<base href="[(site_url)]" />
</head>
<body>
<h2>Template not found! -> [+template+]</h2>
/* Check the setting of plugin;-) */
</body>
</html>
_TPLNOTFOUND_;
//Image ext
$imgExts=array('jpe?g','gif','png','gif');
//image filename prefix
$imgPrefix='.mcthumb.';
// Debug mode
global $MC_debug;
$MC_debug = isset($debug) && ($debug == 1 || $debug == 'yes') ? true:false;
//------------------------------------------------------ Function
//-----------------------------------------------------
// add Event function
//
// $fEvent : string : event name
// $fPlugin : string : plugin name
// return : none :
//
// *** information ***
// 一部バージョンの $modx->addEventListener はバグのダメ動作しない(modx <=0.9.6.2 ,modx = 1.0.0)
// またこの独自関数ではイベントが既に登録されている場合、追記しないようにした
//
//-----------------------------------------------------
if (!function_exists('addEvent')){
function addEvent($fEvent,$fPlugin){
global $modx;
$el= &$modx->pluginEvent[$fEvent];
if (empty ($el)){
$modx->pluginEvent[$fEvent]= array ();
$el= &$modx->pluginEvent[$fEvent];
}
foreach( $el as $val){
if( $fPlugin == $val ){return;}
}
MC_pnt('Adding event',"Event:${fEvent}\nPlugin:${fPlugin}\n");
array_push($el, $fPlugin);
}
}
//-----------------------------------------------------
// Print Eventlog function
//
// $fSubject : string : event name
// $fBody : string : plugin name
// $fMode : int : 0=error,1=debug(defult=1)
// return : none :
//
//-----------------------------------------------------
if (!function_exists('MC_pnt')){
function MC_pnt($fSubject,$fBody,$fMode=1){
global $modx;
global $MC_debug;
if( $fMode == 0 || $MC_debug == true ){
$prefix = '[' . (($fMode==1) ? "Debug" : "Error") . '] MobileConverter : ';
$type = ($fMode==1) ? 1:3;
$modx->logEvent(1, $type, highlight_string($fBody,true), $prefix.$fSubject);
}
}
}
//-----------------------------------------------------
// Image chaange function("preg_replace_callback" function's callback)
//
// $fMt : array : replace string
// return : string : replace string
//
//-----------------------------------------------------
if (!function_exists('MC_ChangeImgFilename')){
function MC_ChangeImgFilename($fMt){
global $modx;
$mcConf = $modx->config['MobileConverterConf'];
if(! preg_match('/src=["\']([^"\']*?)?([^\/"\']+)\.([^\.\/"\'>]+)["\']/i',$fMt[0],$mt) ){
if(! preg_match('/src=([^ \>]*\/)?([^ \/\>]+)\.([^\. \>]+)/i',$fMt[0],$mt) ){ // 「'"」で囲ってない場合
return $fMt[0];
}
}
$imgPath=$mt[1];
$imgName=$mt[2];
$imgExt=$mt[3];
//Ext check
$imgcheck=false;
foreach( $mcConf['imgExts'] as $val)
if( preg_match('/'.$val.'$/i',$imgExt) ){
$imgcheck=true;
break;
}
if($imgcheck != true ) return $fMt[0];
//変換対象のパス確認
$flag=false;
foreach( $mcConf['imgPath'] as $key => $val ){
if( $val == '/' || strstr($imgPath,$val) !== false){
$imgNo = $key;
$flag = true;
break;
}
}
MC_pnt('Imaga path except list',"Except list:".print_r($mcConf['imgPathExcept'],true));
foreach( $mcConf['imgPathExcept'] as $key => $val ){
//例外処理
MC_pnt('Imaga path except',"Path:$imgPath\nExcept:$val\n");
if( $val != '' && strstr($imgPath,$val) !== false){
$flag = false;
break;
}
}
if(! $flag ) return $fMt[0];
//本体画像の存在確認
$realFile = realpath(MODX_BASE_PATH . $imgPath . $imgName . '.' . $imgExt );
if(! is_file($realFile) ){
return $fMt[0];
}
$realFileTime = filemtime($realFile); //ファイルの更新時間
//拡張子の調整
$tmpImgType=isset($mcConf['imgType'][$imgNo])?$mcConf['imgType'][$imgNo]:$mcConf['imgType'][0];
if( $tmpImgType != 'inherit' ){
$imgExt=$tmpImgType;
}
//パスの計算
if( isset($mcConf['imgNum'])){
$addNum = $mcConf['imgNum'].'_';
}else{
$addNum = '';
}
if( $mcConf['thumbImgPath'] === false ){
$chgPath = $imgPath;
$chgFile = $mcConf['imgPrefix'] . $mcConf['groupNo'] . '_' . $addNum . $imgName .'.'. $imgExt;
}else{
$chgPath = $mcConf['thumbImgPath'];
$chgFile = $mcConf['imgPrefix'] . $mcConf['groupNo'] . '_' . $addNum . str_replace('/','_',$imgPath) . $imgName .'.'. $imgExt;
}
$realChgFile = realpath(MODX_BASE_PATH . $chgPath) . '/' . $chgFile;
if( $realChgFile == $chgFile ){
MC_pnt('Cache path not found','PATH:'.MODX_BASE_PATH . $chgPath,0);
return $fMt[0];
}
$chgFile= $chgPath . $chgFile;
MC_pnt('Cahe image path','PATH:'.$realChgFile);
//変換画像作成
if(! is_file($realChgFile) || is_file($realChgFile) && filemtime($realChgFile) < $realFileTime ){
$img=imagecreatefromstring(file_get_contents($realFile));
//リサイズ計算
if( isset($mcConf['imgMaxX'][$imgNo]) ){
$maxX = $mcConf['imgMaxX'][$imgNo];
}else{
$maxX = $mcConf['imgMaxX'][0]; //配列がなければ0をデフォルトの値にする
}
if( isset($mcConf['imgMaxY'][$imgNo]) ){
$maxY = $mcConf['imgMaxY'][$imgNo];
}else{
$maxY = $mcConf['imgMaxY'][0]; //配列がなければ0をデフォルトの値にする
}
$imgX = imagesx($img);
$imgY = imagesy($img);
$toX=$imgX;
$toY=$imgY;
$percentFlag=false;
//パーセントで拡大縮小
if( substr($maxX,-1) == '%' ){
$toX = (int)($imgX * ( (int)substr($maxX,0,-1) / 100 ));
$percentFlag=true;
}
if( substr($maxY,-1) == '%' ){
$toY = (int)($imgY * ( (int)substr($maxY,0,-1) / 100 ));
$percentFlag=true;
}
//ピクセルで縮小
if( ! $percentFlag ){
if( $maxX != 0 && $maxX < $imgX ){
$toX = $maxX;
$toY = (int)($imgY * ($maxX / $imgX));
}
if( $maxY != 0 && $maxY < $imgY ){
$tmpX = (int)($imgX * ($maxY / $imgY));
if( $maxX > $tmpX ){
$toX = $tmpX;
$toY = $maxY;
}
}
}
if( $toX != 0 && $toY != 0){ //リサイズ実行
$newimg=imagecreatetruecolor($toX,$toY);
imagecopyresampled($newimg,$img,0,0,0,0,$toX,$toY,$imgX,$imgY);
imagedestroy($img);
$img = $newimg;
}
switch($imgExt){
case 'gif': // make gif
if( function_exists('imagegif'))
if( ! imagegif($img,$realChgFile))
$modx->logEvent(1, 1, 'Failed make gif image:'.$realChgFile, 'MobileConverter');
break;
case 'png': // make png
if( function_exists('imagepng'))
if( ! imagepng($img,$realChgFile))
$modx->logEvent(1, 1, 'Failed make png image:'.$realChgFile, 'MobileConverter');
break;
case 'jpg':
case 'jpeg':// make jpg
if( function_exists('imagejpeg'))
if( ! imagejpeg($img,$realChgFile))
$modx->logEvent(1, 1, 'Failed make jpg image:'.$realChgFile, 'MobileConverter');
break;
}
}
$newA = preg_replace('/src=["\']?[^"\' >]+["\']?/i',"src='$chgFile'",$fMt[0]);
//erase height and width
$newA = preg_replace('/width=[^ >]+/i','',$newA);
$newA = preg_replace('/height=[^ >]+/i','',$newA);
return $newA;
}
}
//---------------------------------------------------------- Main
//------------------------------------------------------ イベントの追加
if( $this->Event->name == 'OnWebPageInit' || $this->Event->name == 'OnPageNotFound'){
addEvent('OnLoadWebDocument', $MyName);
addEvent('OnLoadWebPageCache', $MyName);
}
//------------------------------------------------------ グループ、ルールのマッチ処理
if( $this->Event->name == 'OnLoadWebDocument' ||
$this->Event->name == 'OnLoadWebPageCache' ||
$this->Event->name == 'OnPageNotFound'){
$id = $this->documentIdentifier; //Current document id
// トップ階層までリソースIDを求める
$ids = array();
array_push($ids,$id);
while( $id != 0 ){
$parentData = $modx->getParent($id,0,'id');
if(! $parentData ){
break;
}
$id = $parentData['id'];
array_push($ids,$id);
}
MC_pnt('Target IDs','$ids='."\n".print_r($ids,true));
$mcFlag=false;
for( $i=1 ; isset(${'g'.$i.'_targetDoc'}) || isset(${'g'.$i.'_targetTemplate'});$i++ ){
//リソースIDかテンプレートのターゲット判定(テンプレート優先で排他制御)
if( isset(${'g'.$i.'_targetTemplate'}) ){
//テンプレートがターゲットになるか判定
$sql = 'SELECT c.id, t.templatename
FROM '.$modx->getFullTableName("site_content") .' as c,
'.$modx->getFullTableName("site_templates").' as t
WHERE c.template = t.id
AND c.id = '.(int)$ids[0];
MC_pnt('Template check SQL','SQL:'.$sql);
$rs = $this->db->query($sql);
if( $row = $this->db->getRow($rs) ){
if( $row['templatename'] == ${'g'.$i.'_targetTemplate'}){
MC_pnt('Template match!','$temp1:'.${'g'.$i.'_targetTemplate'}."\n".'$temp2:'.$row['templatename']);
$mcFlag= true;
}
}
}else{
//リソースがターゲットになるか判定
if( ${'g'.$i.'_targetDoc'} == '' || (string)${'g'.$i.'_targetDoc'} == '0'){
// 0の場合はON判定
$mcFlag= true;
}else{
$targetDocs=explode(',',${'g'.$i.'_targetDoc'});
foreach ($targetDocs as $targetDoc){
if(! preg_match('/^[+-]?[0-9]+[rR]?$/',$targetDoc)){
MC_pnt('Syntax error in target resouse(document) IDs','$targetDoc:'.$targetDoc,0);
continue;
}
$keyPos = stripos($targetDoc,'r');
if( $keyPos !== false){
$recFlag = substr($targetDoc,-1,1); //後ろの記号を取得
$targetDoc = substr($targetDoc,0,-1); //後ろのrRは削除
}else{
//再帰不要なとき
if( $targetDoc == 0 || $ids[0] == $targetDoc){
$mcFlag=true;
}elseif( $targetDoc < 0 && $ids[0] == abs($targetDoc)){
$mcFlag=false;
}
continue;
}
//再帰が必要なとき
foreach( $ids as $id ){
if( $recFlag == 'R' && $ids[0] == $id ){ continue; } //大文字Rの時は対象ドキュメントを含まない
if( $targetDoc >= 0 && $id == $targetDoc ){
$mcFlag=true;
break;
}
if( $targetDoc < 0 && $id == abs($targetDoc)){
$mcFlag=false;
break;
}
}
}
}
}
if( $mcFlag == true ){
MC_pnt('Resouce Match!',"Group:$i\nResource:${ids[0]}\n");
//該当グループのルールにマッチするか判定
$targetVal = isset(${'g'.$i.'_targetKey'}) ? $_SERVER[${'g'.$i.'_targetKey'}] : $_SERVER['HTTP_USER_AGENT'];
//while( isset(${'g'.$i.'_'.$j.'_matchStr'}) ){
for( $j=1; isset(${'g'.$i.'_'.$j.'_matchStr'}) ;$j++){
$matchStrs = ${'g'.$i.'_'.$j.'_matchStr'};
if( $matchStrs == '' ) continue;
$matchStrs = str_replace('\,','\#44;',$matchStrs); // \,を置換
$matchStrs = explode(',',$matchStrs);
foreach ($matchStrs as $matchStr){
$mcFlag = true; //ここでいったんtrue
$matchStr = str_replace('\#44;',',',$matchStr); // ,に戻す
$matchStr = str_replace('\+','\#43;',$matchStr); // \|を置換
$matchSubStrs = explode('+',$matchStr);
foreach ($matchSubStrs as $matchSubStr){
$matchSubStr = str_replace('\#43;','+',$matchSubStr); // |に戻す
if( stripos($matchSubStr,'/') === 0 ){
//正規表現処理
if( preg_match($matchSubStr,$targetVal) != 0 ){continue;}
}else{
//普通のマッチ処理
if( stripos($matchSubStr,'\/') === 0 ){ // 先頭の\/の処理
$matchSubStr = substr($matchSubStr,1);
}
if( stristr($targetVal,$matchSubStr) !== false ){continue;}
}
$mcFlag = false;
}
if( $mcFlag == true ){
MC_pnt('Group,Rule match.',"groupno=$i\nrule=$j\nAgent=$targetVal");
$MC_eof = isset($enableOutEffect) ? $enableOutEffect : 'no';
$MC_eof = isset(${'g'.$i.'_enableOutEffect'}) ? ${'g'.$i.'_enableOutEffect'} : $MC_eof;
if( $MC_eof == 'yes' ){
$MC_Enable = isset($_COOKIE['MC_Eneble']) ? $_COOKIE['MC_Eneble'] : 'on';
if( isset($_REQUEST['MC_Eneble']) ){
if( $_REQUEST['MC_Eneble'] == 'on' ){
$MC_Enable = 'on';
}else{
$MC_Enable = 'off';
}
}
if( !isset($_COOKIE['MC_Eneble']) || (isset($_COOKIE['MC_Eneble']) && $_COOKIE['MC_Eneble'] != $MC_Enable) ){
setcookie('MC_Eneble',$MC_Enable);
}
if( $MC_Enable == 'off' ){
MC_pnt('MC Skip.',"MC Skip");
break 3; //全てのループを抜ける(MCは機能しない)
}
}
$groupNo = $i;
$ruleNo = $j;
break 3; //全てのループを抜ける
}
}
}
}
}
}
//------------------------------------------------------ 専用404ページの用意
if( $this->Event->name == 'OnPageNotFound' ){
if( isset(${'g'.$groupNo.'_404Resource'}) && preg_match('/^[0-9]+$/',${'g'.$groupNo.'_404Resource'}) ){
$this->config['error_page'] = ${'g'.$groupNo.'_404Resource'};
}
}
//------------------------------------------------------ OnWebPagePrerenderイベント準備
if( $this->Event->name == 'OnLoadWebDocument' ||
$this->Event->name == 'OnLoadWebPageCache'){
unset($modx->config['MobileConverterConf']); ///2回実行対策(いらないかも)
if( isset($groupNo) ){
//次のイベントで利用する変数の決定
$mcConf = array();
$mcConf['groupNo'] = $groupNo; //グループNo
$mcConf['ruleNo'] = $ruleNo; //ルールNo
addEvent('OnWebPagePrerender', $MyName);
}elseif( $enableCharConvIfnoElect == 'yes' ){ //文字コード変換だけ行う場合
$mcConf = array();
$mcConf['enableCharConv'] = true;
$mcConf['charset'] = isset($charset) ? $charset : 'Shift_JIS';
addEvent('OnWebPagePrerender', $MyName);
}
}
//------------------------------------------------------ テンプレート変換
if( isset($groupNo) &&
($this->Event->name == 'OnLoadWebDocument' ||
$this->Event->name == 'OnLoadWebPageCache')){
//※ここに独自のキャッシュ機能を入れたらいいかもしれない
// 本気でやる場合、問題点として認証チェック、公開日チェック等も独自で実装する必要がある
// 適当にやる場合テンプレートのキャッシュだけでいける(ただし、効果は微妙かもしれない)
//キャッシュは強制的にOFF
//※ONの場合、最初に使われたテンプレートがキャッシュされ、パターンにマッチしない場合、そちらが利用される
$modx->documentObject['cacheable'] = 0;
//テンプレートの読み込み
$switchTemplate = ${'g'.$groupNo.'_'.$ruleNo.'_template'};
$tbl = $modx->getFullTableName("site_templates");
$whr = 'templatename=\''.$switchTemplate.'\'';
if( $rs = $modx->db->select('id,content',$tbl,$whr) ){
if( $resource = $modx->fetchRow($rs) ){
$this->documentObject['template'] = $resource['id'];
$this->documentContent = $resource['content'];
}else{
MC_pnt('Template error','Template not found:'.$switchTemplate,0);
$bf= array('[+charset+]','[+template+]');
$af= array($modx->config['modx_charset'],$switchTemplate);
$TemplateNotFound = str_replace($bf,$af,$TemplateNotFound);
$this->documentContent = $TemplateNotFound;
}
}
//文字コードの決定
$switchCharset = ${'g'.$groupNo.'_'.$ruleNo.'_charset'};
if( $switchCharset != '' ){
$mcConf['charset'] = $switchCharset;
}else{
$mcConf['charset'] = isset($charset) ? $charset : 'Shift_JIS';
}
//文字コード変換の有無
$mcConf['enableCharConv'] = isset($enableCharConv) ? $enableCharConv : 'no';
$mcConf['enableCharConv'] = isset(${'g'.$groupNo.'_'.$ruleNo.'_enableCharConv'}) ? ${'g'.$groupNo.'_'.$ruleNo.'_enableCharConv'} : $mcConf['enableCharConv'];
if( $mcConf['enableCharConv'] == 'no' ){
$mcConf['enableCharConv'] = false;
}else{
$mcConf['enableCharConv'] = true;
}
//画像変換の情報決定
$switchImgType = ${'g'.$groupNo.'_'.$ruleNo.'_imgType'};
if( isset($switchImgType) && $switchImgType != '' ){
$mcConf['imgType'] = explode(',',$switchImgType);
$mcConf['imgExts'] = $imgExts;
$mcConf['imgPrefix'] = $imgPrefix;
$imgPath = isset($imgPath) && $imgPath != '' ? $imgPath : '/';
$imgPath = isset( ${'g'.$groupNo.'_imgPath'} ) ? ${'g'.$groupNo.'_imgPath'} : $imgPath;
$imgPathExcept = isset($imgPathExcept) && $imgPathExcept != '' ? $imgPathExcept : '';
$imgPathExcept = isset( ${'g'.$groupNo.'_imgPathExcept'} ) ? ${'g'.$groupNo.'_imgPathExcept'} : $imgPathExcept;
$imgMaxX = isset($imgMaxX) && $imgMaxX != '' ? $imgMaxX : 0;
$imgMaxX = isset( ${'g'.$groupNo.'_imgMaxX'} ) ? ${'g'.$groupNo.'_imgMaxX'} : $imgMaxX;
$imgMaxX = isset( ${'g'.$groupNo.'_'.$ruleNo.'_imgMaxX'} ) ? ${'g'.$groupNo.'_'.$ruleNo.'_imgMaxX'} : $imgMaxX;
$imgMaxY = isset($imgMaxY) && $imgMaxY != '' ? $imgMaxY : 0;
$imgMaxY = isset( ${'g'.$groupNo.'_imgMaxY'} ) ? ${'g'.$groupNo.'_imgMaxY'} : $imgMaxY;
$imgMaxY = isset( ${'g'.$groupNo.'_'.$ruleNo.'_imgMaxY'} ) ? ${'g'.$groupNo.'_'.$ruleNo.'_imgMaxY'} : $imgMaxY;
$mcConf['imgPath'] = explode(',',$imgPath);
$mcConf['imgPathExcept'] = explode(',',$imgPathExcept);
$mcConf['imgMaxX'] = explode(',',$imgMaxX);
$mcConf['imgMaxY'] = explode(',',$imgMaxY);
if( isset(${'g'.$groupNo.'_'.$ruleNo.'_imgMaxX'}) || isset(${'g'.$groupNo.'_'.$ruleNo.'_imgMaxY'})){
$mcConf['imgNum'] = $ruleNo;;
}
$mcConf['thumbImgPath'] = isset($thumbImgPath) && $thumbImgPath != '' ? $thumbImgPath : false; //Thumbnail save path
$mcConf['thumbImgPath'] = isset(${'g'.$groupNo.'_thumbImgPath'}) ? ${'g'.$groupNo.'_thumbImgPath'} : $mcConf['thumbImgPath'];
}
$modx->config['MobileConverterConf'] = $mcConf; //Value transport next event.
//OnLoadWebPageCache時はparserを一度も通らないので実行
if( $modx->Event->name == 'OnLoadWebPageCache'){
$this->documentContent= $this->parseDocumentSource($this->documentContent);
}
}
//------------------------------------------------------ 画像変換、文字コード変換
if( $this->Event->name == 'OnWebPagePrerender' ){
//Set value prev event
$mcConf = $modx->config['MobileConverterConf'];
//画像変換
if( isset($mcConf['imgType'])){
$modx->documentOutput = preg_replace_callback('/<img [^>]+>/i','MC_ChangeImgFilename',$modx->documentOutput);
}
// Convert charset
if( $mcConf['enableCharConv'] == true){
// Change HTTP header's Content-Type
//------別の方法
//$addHeader='';
//$headers=headers_list();
//foreach($headers as $val)
// if( strpos($val,'Content-Type:') !== false ){
// $addHeader=substr($val,0,strrpos($val,'=')+1) . $mobileCharset;
// break;
//}
//header($addHeader,true);
$type= !empty($modx->contentTypes[$modx->documentIdentifier]) ? $modx->contentTypes[$modx->documentIdentifier] : "text/html";
header('Content-Type: ' . $type . '; charset=' . $mcConf['charset'],true);
// Shift_JIS -> SJIS
if( stripos($mcConf['charset'] , 'Shift_JIS') !== false) $mcConf['charset'] = 'SJIS';
$modx->documentOutput = mb_convert_encoding($modx->documentOutput,$mcConf['charset'],$modx->config['modx_charset']);
}
}