-
Notifications
You must be signed in to change notification settings - Fork 0
/
futaba3pio.php
123 lines (104 loc) · 6.71 KB
/
futaba3pio.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
<?php
/**
* Pixmicat! PIO å…¬ç”¨ç¨‹å¼ - Pixmicat!-Log -> Pixmciat-PIO (Log) è³‡æ–™æ ¼å¼è½‰æ›å™¨
*
* 本程å¼å¯ä»¥è‡ª Log 版轉æ›æ ¼å¼è‡ª PIO 版 Log 資料來æºã€‚
*
* 注æ„:本程å¼æ˜¯çµ¦ Log 版舊程å¼ä½¿ç”¨ä»¥è½‰æ›ï¼Œéžç›´æŽ¥ç”¨åœ¨ PIO 新版上é¢
*
* @package PMCUtility
* @version $Id$
* @date $Date$
*/
define("PHP_DIRECTORY", '../../core/'); // yotsubanome "C:\windows\system\"
include_once(PHP_DIRECTORY.'config.php');
define('DEL_ZOMBIE', true); // å¦‚æžœæœ‰æ–‡ç« æ²’æœ‰å‡ºç¾åœ¨æ¨¹ç‹€çµæ§‹ï¼Œæ˜¯å¦ä¸è¦è½‰æ›ç›´æŽ¥åˆªé™¤ï¼Ÿ
define('SAVE_LOG', true); // 是å¦å„²å˜æ–°çµæ§‹ (舊çµæ§‹å°‡ä¿ç•™ä¸¦æ›´å)
define('LOGFILE', "img.csv_loog");
define('TREEFILE', "tree.csv_loog");
// å„資料儲å˜æª”ä½ç½®
$logimg = file(LOGFILE); $logimg_cnt = count($logimg);
$trees = array(); // æ–‡ç« å›žæ‡‰å°æ‡‰ç·¨è™Ÿé™£åˆ— (回應No. => 首篇No.)
$logtree = array_map('rtrim', file(TREEFILE));
foreach($logtree as $treeline){ // 解æžæ¨¹ç‹€çµæ§‹è£½æˆå°æ‡‰ç´¢å¼•
if($treeline=='') continue;
$tline = explode(',', $treeline); $tline_cnt = count($tline);
$trees[$tline[0]] = 0;
for($t = 1; $t < $tline_cnt; $t++){ $trees[$tline[$t]] = $tline[0]; }
}
unset($logtree);
// 圖檔å˜æ”¾ä½ç½®
$dirimg = realpath('.').DIRECTORY_SEPARATOR.IMG_DIR;
/* å–得圖檔的寬長以å˜å…¥è³‡æ–™ */
function getImageWH($imgname){
global $dirimg;
$imgpath = $dirimg.$imgname;
if(!file_exists($imgpath)) return array(0, 0);
list($width, $height,) = getimagesize($imgpath);
return array($width, $height); // 回傳寬高陣列
}
/* å–得圖檔的檔案大å°å—串 (å–®ä½ KB) */
function getImageSizeText($imgname){
global $dirimg;
$imgpath = $dirimg.$imgname;
if(!file_exists($imgpath)) return false;
$imgsize = filesize($imgpath);
return $imgsize = ($imgsize>=1024) ? (int)($imgsize/1024).' KB' : $imgsize.' B'; // KBå’ŒB的判別 // 回傳檔案大å°å—串
}
/* å–得回應的å°è±¡ç·¨è™Ÿ */
function getReplyTargetNo($no){
global $trees;
if(isset($trees[$no])) return $trees[$no];
return false;
}
/* 更改 log 檔çµæ§‹ */
// OLD: 編號,時間 (ID),å稱,E-Mail,標題,內文,狀態旗標,主機ä½ç½®,ç·¨ç¢¼å¾Œæ–‡ç« å¯†ç¢¼,é™„åŠ åœ–æª”é¡žåž‹,é 覽圖寬,é 覽圖長,Unix時間撮記,é™„åŠ åœ–æª”MD5,
// SUPER DUPER UBER OLD:
// 0$no,1$now,2$name,3$email,4$sub,5$com,6$url,7$host,8$pwd,9$ext,10$w,11$h,12$time,13$chk
// (futaba)
// SUPER DUPER OLD:
// 0$no,1$now,2$name,3$email,4$sub,5$com,6$url,7$host,8$pwd,9$ext,10$w,11$h,12$time,13$chk,14$ip
// (early yotsubanome)
// SUPER OLD:
// 0$no,1$now,2$name,3$email,4$sub,5$com,6$url,7$host,8$pwd,9$ext,10$w,11$h,12$time,13$chk,14$ip,15$filename,16$mime
// (old yotsubanome)
// OLD:
// 0$no,1$now,2$name,3$email,4$sub,5$com,6$url,7$host,8$pwd,9$ext,10$w,11$h,12$time,13$chk,14$imgsize,15$filename,16$imgW,17$imgH,18$category,19$resto
// (older new yotsubanome)
// NEW: 編號,回應目標編號,é™„åŠ åœ–æª”MD5,類別標籤,Unix時間撮記,é™„åŠ åœ–æª”é¡žåž‹,圖檔寬,圖檔長,圖檔大å°,é 覽圖寬,é 覽圖長,ç·¨ç¢¼å¾Œæ–‡ç« å¯†ç¢¼,時間 (ID),å稱,E-mail,標題,內文,主機ä½ç½®,狀態旗標,
// NEW:
// 0$no,1$resto,2$chk,3$category,4$time,5$ext,6$imgw,7$imgh,8$imgsize,9$filename,10$w,11$h,12$pwd,13$now,14$name,15$email,16$sub,17$com,18$host,19$url
// ↑ = ↓ the line above is equal to the line below (The line above is the old futaba variable names, and the line below is the new yotsubanome variable names.)
// 0$no,1$resto,2$md5chksum,3$category,4$tim,5$ext,6$imgw,7$imgh,8$imgsize,9$filename,10$tw,11$th,12$pwd,13$now,14$name,15$email,16$sub,17$com,18$host,19$status
// (new yotsubanome)
header('Content-Type: text/plain; charset=utf-8');
$newLine = array(); // æ–°è³‡æ–™æ ¼å¼
$countda = count(explode(',', $logimg[0]));
if(count(explode(',', $logimg[0])) != 15 && count(explode(',', $logimg[0])) != 17 && count(explode(',', $logimg[0])) != 19){
if($countda = 21) die('File structure error. It\'s already a PIO structure. ['.$countda.']'.var_dump($logimg));
else die('File structure error. ['.$countda.']'.var_dump($logimg));
}
for($i = 0; $i < $logimg_cnt; $i++){
$l = explode(',', $logimg[$i]); // èˆŠè³‡æ–™æ ¼å¼ (用逗號拆開)
$s = getImageWH($l[12].$l[9]); // 圖檔寬長 (寬, 長)
$l[6] = str_replace('_THREADSTOP_', '_TS_', $l[6]); // 討論串åœæ¢æ——標自 _THREADSTOP_ 改為 _TS_
$l[2] = preg_replace('/<(.*?)>/', '', $l[2]); // name crap that breaks HTTP
$l[2] = preg_replace('/ /', '', $l[2]); // name crap that breaks HTTP
$l[2] = preg_replace('/◆四葉(.*?)##(.*?)##/', '', $l[2]); // name crap that breaks HTTP
if(strstr($l[14], "\n")){ $l[15] = $l[16] = $l[17] = $l[18] = $l[19] = ''; } // from futaba
if(strstr($l[14], ".") && $l[15] = false || !strstr($l[14], "KB") && !strstr($l[14], "B")){ $l[15] = $l[16] = $l[17] = $l[18] = $l[19] = ''; } // from early yotsubanome
if(strstr($l[14], ".") && strstr($l[16], "/") || !strstr($l[14], "KB") && !strstr($l[14], "B")){ $l[14] = $l[16] = ''; } // from old yotsubanome
//++++!if(strstr($l[1], "1969"))
if(!DEL_ZOMBIE || getReplyTargetNo($l[0]) !== false && $l[1] !== false) $newLine[] = implode(',', array($l[0], getReplyTargetNo($l[0]), $l[13], '', $l[12], $l[9], $s[0], $s[1], getImageSizeText($l[12].$l[9]), $l[15], (int) $l[10], (int) $l[11], $l[8], $l[1], $l[2], $l[3], $l[4], $l[5], $l[7], $l[6], ''))."\r\n";
}
$writeContent = implode('', $newLine);
if(SAVE_LOG){
rename(LOGFILE, LOGFILE.'.old');
$fs = fopen(LOGFILE, 'w');
fwrite($fs, $writeContent);
fclose($fs);
die('File save OK. The old file already renamed.');
}else{
echo $writeContent;
}
?>