]> 4ch.mooo.com Git - test.git/blob - lib/lib_pio.cond.php
modified: yotsubanome.php
[test.git] / lib / lib_pio.cond.php
1 <?php\r
2 /**\r
3  * PIO Condition Object\r
4  *\r
5  * 判斷文章是否符合刪除條件並列出刪除編號\r
6  * \r
7  * @package PMCLibrary\r
8  * @version $Id: lib_pio.cond.php 578 2008-01-13 03:51:18Z roytam1 $\r
9  * @date $Date: 2008-01-13 11:51:18 +0800 (星期日, 13 一月 2008) $\r
10  */\r
11 \r
12 /* 以總文章篇數作為刪除判斷 */\r
13 class ByPostCountCondition{\r
14         /*public static */function check($type, $limit){\r
15                 global $PIO;\r
16                 return $PIO->postCount() >= $limit * ($type=='predict' ? 0.95 : 1);\r
17         }\r
18 \r
19         /*public static */function listee($type, $limit){\r
20                 global $PIO;\r
21                 return $PIO->fetchPostList(0, intval($limit * ($type=='predict' ? 0.95 : 1)) - 1, $limit);\r
22         }\r
23 \r
24         /*public static */function info($limit){\r
25                 global $PIO;\r
26                 return "ByPostCountCondition: ".($pcnt=$PIO->postCount()).'/'.$limit.sprintf(' (%.2f%%)',($pcnt/$limit*100));\r
27         }\r
28 }\r
29 \r
30 /* 以總討論串數作為刪除判斷 */\r
31 class ByThreadCountCondition{\r
32         /*public static */function check($type, $limit){\r
33                 global $PIO;\r
34                 return $PIO->threadCount() >= ($type=='predict' ? $limit * 0.95 : 1);\r
35         }\r
36 \r
37         /*public static */function listee($type, $limit){\r
38                 global $PIO;\r
39                 return $PIO->fetchThreadList(intval($limit * ($type=='predict' ? 0.95 : 1)), $limit);\r
40         }\r
41 \r
42         /*public static */function info($limit){\r
43                 global $PIO;\r
44                 return "ByThreadCountCondition: ".($tcnt=$PIO->threadCount()).'/'.$limit.sprintf(' (%.2f%%)',($tcnt/$limit*100));\r
45         }\r
46 }\r
47 \r
48 /* 以討論串生存時間作為刪除判斷 */\r
49 class ByThreadAliveTimeCondition{\r
50         /*public static */function check($type, $limit){\r
51                 global $PIO;\r
52                 $oldestThreadNo = $PIO->fetchThreadList($PIO->threadCount() - 1, 1, true); // 最舊討論串編號\r
53                 $oldestThread = $PIO->fetchPosts($oldestThreadNo);\r
54                 return (time() - substr($oldestThread[0]['tim'], 0, 10) >= 86400 * $limit * ($type=='predict' ? 0.95 : 1));\r
55         }\r
56 \r
57         /*public static */function listee($type, $limit){\r
58                 global $PIO;\r
59                 $ThreadNo = $PIO->fetchThreadList(0, 0, true); sort($ThreadNo); // 討論串編號陣列 (由舊到新)\r
60                 $NowTime = time();\r
61                 $i = 0;\r
62                 foreach($ThreadNo as $t){\r
63                         $post = $PIO->fetchPosts($t);\r
64                         if($NowTime - substr($post[0]['tim'], 0, 10) < 86400 * $limit * ($type=='predict' ? 0.95 : 1)) break; // 時間不符合\r
65                         $i++;\r
66                 }\r
67                 if(count($ThreadNo)===$i){ $i--; } // 保留最新的一篇避免全部刪除\r
68                 return array_slice($ThreadNo, 0, $i);\r
69         }\r
70 \r
71         /*public static */function info($limit){\r
72                 return "ByThreadAliveTimeCondition: ".$limit.' day(s)';\r
73         }\r
74 }\r
75 ?>