-
Notifications
You must be signed in to change notification settings - Fork 1
/
inc.php
57 lines (48 loc) · 1.35 KB
/
inc.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
<?php defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
function handleComments() {
global $wpdb;
$comments = $wpdb->get_results( "SELECT c.comment_ID, c.comment_post_ID, c.comment_date, p.post_date
FROM $wpdb->comments c
JOIN $wpdb->posts p ON c.comment_post_ID = p.ID
WHERE c.comment_approved = 1 AND p.post_status = 'publish'" );
list( $from, $to ) = getFromAndToDates();
$total = 0;
foreach ( $comments as $comment ) {
$total ++;
$post_date = strtotime( $comment->post_date );
$_from = $from;
if ( $from < $post_date ) {
$_from = $post_date;
}
$_to = $to;
if ( $to < $post_date ) {
$_to = $post_date + 60;
}
$time = rand( $_from, $_to );
$time = date( "Y-m-d H:i:s", $time );
$wpdb->query(
$wpdb->prepare(
"UPDATE $wpdb->comments SET comment_date ='%s', comment_date_gmt='%s' WHERE comment_ID = %d",
$time,
get_gmt_from_date( $time ),
$comment->comment_ID
)
);
}
return $total;
}
function getFromAndToDates() {
$from = $_POST['distribute'];
$to = current_time( 'timestamp', 0 );
$now = current_time( 'timestamp', 0 );
if ( $from == 0 ) {
$range = explode( '-', $_POST['range'] );
if ( count( $range ) == 2 ) {
$from = strtotime( $range[0], $now );
$to = strtotime( $range[1], $now );
} else {
$from = strtotime( '-3 hours', $now );
}
}
return [ $from, $to ];
}