3 * Pixmicat! PIO 公用程式 - Pixmicat!-Log -> Pixmciat-PIO (Log) 資料格式轉換器
\r
5 * 本程式可以自 Log 版轉換格式自 PIO 版 Log 資料來源。
\r
7 * 注意:本程式是給 Log 版舊程式使用以轉換,非直接用在 PIO 新版上面
\r
9 * @package PMCUtility
\r
14 define("PHP_DIRECTORY", '../../core/'); // yotsubanome "C:\windows\system\"
\r
15 include_once(PHP_DIRECTORY.'config.php');
\r
16 define('DEL_ZOMBIE', true); // 如果有文章沒有出現在樹狀結構,是否不要轉換直接刪除?
\r
17 define('SAVE_LOG', true); // 是否儲存新結構 (舊結構將保留並更名)
\r
18 define('LOGFILE', "img.csv_loog");
\r
19 define('TREEFILE', "tree.csv_loog");
\r
22 $logimg = file(LOGFILE); $logimg_cnt = count($logimg);
\r
23 $trees = array(); // 文章回應對應編號陣列 (回應No. => 首篇No.)
\r
24 $logtree = array_map('rtrim', file(TREEFILE));
\r
25 foreach($logtree as $treeline){ // 解析樹狀結構製成對應索引
\r
26 if($treeline=='') continue;
\r
27 $tline = explode(',', $treeline); $tline_cnt = count($tline);
\r
28 $trees[$tline[0]] = 0;
\r
29 for($t = 1; $t < $tline_cnt; $t++){ $trees[$tline[$t]] = $tline[0]; }
\r
34 $dirimg = realpath('.').DIRECTORY_SEPARATOR.IMG_DIR;
\r
37 function getImageWH($imgname){
\r
40 $imgpath = $dirimg.$imgname;
\r
41 if(!file_exists($imgpath)) return array(0, 0);
\r
42 list($width, $height,) = getimagesize($imgpath);
\r
43 return array($width, $height); // 回傳寬高陣列
\r
46 /* 取得圖檔的檔案大小字串 (單位 KB) */
\r
47 function getImageSizeText($imgname){
\r
50 $imgpath = $dirimg.$imgname;
\r
51 if(!file_exists($imgpath)) return false;
\r
52 $imgsize = filesize($imgpath);
\r
53 return $imgsize = ($imgsize>=1024) ? (int)($imgsize/1024).' KB' : $imgsize.' B'; // KB和B的判別 // 回傳檔案大小字串
\r
57 function getReplyTargetNo($no){
\r
60 if(isset($trees[$no])) return $trees[$no];
\r
65 // OLD: 編號,時間 (ID),名稱,E-Mail,標題,內文,狀態旗標,主機位置,編碼後文章密碼,附加圖檔類型,預覽圖寬,預覽圖長,Unix時間撮記,附加圖檔MD5,
\r
67 // SUPER DUPER UBER OLD:
\r
68 // 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
\r
72 // 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
\r
73 // (early yotsubanome)
\r
76 // 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
\r
77 // (old yotsubanome)
\r
80 // 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
\r
81 // (older new yotsubanome)
\r
84 // NEW: 編號,回應目標編號,附加圖檔MD5,類別標籤,Unix時間撮記,附加圖檔類型,圖檔寬,圖檔長,圖檔大小,預覽圖寬,預覽圖長,編碼後文章密碼,時間 (ID),名稱,E-mail,標題,內文,主機位置,狀態旗標,
\r
86 // 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
\r
87 // ↑ = ↓ 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.)
\r
88 // 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
\r
89 // (new yotsubanome)
\r
91 header('Content-Type: text/plain; charset=utf-8');
\r
92 $newLine = array(); // 新資料格式
\r
93 $countda = count(explode(',', $logimg[0]));
\r
94 if(count(explode(',', $logimg[0])) != 15 && count(explode(',', $logimg[0])) != 17 && count(explode(',', $logimg[0])) != 19){
\r
95 if($countda = 21) die('File structure error. It\'s already a PIO structure. ['.$countda.']'.var_dump($logimg));
\r
96 else die('File structure error. ['.$countda.']'.var_dump($logimg));
\r
98 for($i = 0; $i < $logimg_cnt; $i++){
\r
99 $l = explode(',', $logimg[$i]); // 舊資料格式 (用逗號拆開)
\r
100 $s = getImageWH($l[12].$l[9]); // 圖檔寬長 (寬, 長)
\r
101 $l[6] = str_replace('_THREADSTOP_', '_TS_', $l[6]); // 討論串停止旗標自 _THREADSTOP_ 改為 _TS_
\r
102 $l[2] = preg_replace('/<(.*?)>/', '', $l[2]); // name crap that breaks HTTP
\r
103 $l[2] = preg_replace('/ /', '', $l[2]); // name crap that breaks HTTP
\r
104 $l[2] = preg_replace('/◆四葉(.*?)##(.*?)##/', '', $l[2]); // name crap that breaks HTTP
\r
105 if(strstr($l[14], "\n")){ $l[15] = $l[16] = $l[17] = $l[18] = $l[19] = ''; } // from futaba
\r
106 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
\r
107 if(strstr($l[14], ".") && strstr($l[16], "/") || !strstr($l[14], "KB") && !strstr($l[14], "B")){ $l[14] = $l[16] = ''; } // from old yotsubanome
\r
108 //++++!if(strstr($l[1], "1969"))
\r
109 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";
\r
112 $writeContent = implode('', $newLine);
\r
115 rename(LOGFILE, LOGFILE.'.old');
\r
116 $fs = fopen(LOGFILE, 'w');
\r
117 fwrite($fs, $writeContent);
\r
119 die('File save OK. The old file already renamed.');
\r
121 echo $writeContent;
\r