2014-05-17 22:01:14 +02:00
< ? php
2014-07-19 20:40:06 +02:00
include 'inc/functions.php' ;
2014-11-22 08:32:22 +01:00
if ( php_sapi_name () == 'fpm-fcgi' ) {
error ( 'Cannot be run directly.' );
}
function last_activity ( $board ) {
// last post
$query = prepare ( sprintf ( " SELECT MAX(time) AS time FROM posts_%s " , $board ));
$query -> execute ();
$row = $query -> fetch ();
$ago = ( new DateTime ) -> sub ( new DateInterval ( 'P1W' ));
$mod_ago = ( new DateTime ) -> sub ( new DateInterval ( 'P2W' ));
$last_activity_date = new DateTime ();
$last_mod_date = new DateTime ();
$last_activity_date -> setTimestamp ( $row [ 'time' ]);
2014-12-03 09:12:38 +01:00
$query = query ( " SELECT id, username FROM mods WHERE boards = ' $board ' AND type = 20 " );
2014-11-22 08:32:22 +01:00
$mods = $query -> fetchAll ();
if ( $mods ) {
$mod = $mods [ 0 ][ 'id' ];
$query = query ( " SELECT MAX(time) AS time FROM modlogs WHERE `mod` = $mod " );
$a = $query -> fetchAll ( PDO :: FETCH_COLUMN );
if ( $a [ 0 ]) {
$last_mod_date -> setTimestamp ( $a [ 0 ]);
if ( ! $row [ 'time' ])
$last_activity_date -> setTimestamp ( $a [ 0 ]);
} else { // no one ever logged in, try board creation time
$query = query ( " SELECT UNIX_TIMESTAMP(time) AS time FROM board_create WHERE uri = ' $board ' " );
$crt = $query -> fetchAll ( PDO :: FETCH_COLUMN );
2015-02-17 01:10:35 +01:00
if ( $crt ) $last_activity_date -> setTimestamp ( $crt [ 0 ]);
2014-11-22 08:32:22 +01:00
$last_mod_date = false ;
}
}
2015-01-29 02:56:49 +01:00
if (( $last_activity_date < $ago or ( $last_mod_date and $last_mod_date < $mod_ago ))) {
2014-11-22 08:32:22 +01:00
return array ( $last_activity_date , $last_mod_date , $mods );
}
else {
return false ;
}
}
$q = query ( " SELECT uri FROM boards " );
$boards = $q -> fetchAll ( PDO :: FETCH_COLUMN );
$delete = array ();
foreach ( $boards as $board ) {
$last_activity = last_activity ( $board );
if ( $last_activity ) {
list ( $last_activity_date , $last_mod_date , $mods ) = $last_activity ;
2014-05-17 22:01:14 +02:00
2014-11-22 08:32:22 +01:00
$last_mod_f = $last_mod_date ? $last_mod_date -> format ( 'Y-m-d H:i:s' ) : '<em>never</em>' ;
$last_activity_f = $last_activity_date ? $last_activity_date -> format ( 'Y-m-d H:i:s' ) : '<em>never</em>' ;
$delete [] = array ( 'board' => $board , 'last_activity_date' => $last_activity_f , 'last_mod' => $last_mod_date , 'last_mod_f' => $last_mod_f );
}
}
$body = Element ( " 8chan/claim.html " , array ( " config " => $config , " delete " => $delete ));
2015-04-25 02:46:53 +02:00
file_write ( " claim.html " , Element ( " page.html " , array ( " config " => $config , " body " => $body , " title " => _ ( " Claim " ), " subtitle " => _ ( " Take deserted boards back from their owners " ))));