You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 1, 2024. It is now read-only.
if (!$wpdb->query("SELECT hit_count FROM $popular_posts_statistics_table WHERE post_id = $postID") && $postID != 1 && !preg_match('/bot|spider|crawler|slurp|curl|^$/i', $_SERVER['HTTP_USER_AGENT'])) { //jeśli nie istnieje rekord hit_count z podanym ID oraz ID nie jest równe 1 oraz odwiedzający nie jest botem
8
-
$result = $wpdb->query("INSERT INTO $popular_posts_statistics_table (post_id, hit_count, date) VALUES ($postID, 1, NOW())"); //dodaje do tablicy id postu, date oraz hit
$hitsnumber = $wpdb->get_results("SELECT hit_count FROM $popular_posts_statistics_table WHERE post_id = $postID", ARRAY_A);
7
+
if (!$wpdb->query($wpdb->prepare("SELECT hit_count FROM $popular_posts_statistics_table WHERE post_id = %d", $postID)) && !preg_match('/bot|spider|crawler|slurp|curl|^$/i', $_SERVER['HTTP_USER_AGENT'])) { //jeśli nie istnieje rekord hit_count z podanym ID oraz ID nie jest równe 1 oraz odwiedzający nie jest botem
8
+
$wpdb->query($wpdb->prepare("INSERT INTO $popular_posts_statistics_table (post_id, hit_count, date) VALUES (%d, 1, NOW())", $postID)); //dodaje do tablicy id postu, date oraz hit
9
+
}elseif (!preg_match('/bot|spider|crawler|slurp|curl|^$/i', $_SERVER['HTTP_USER_AGENT'])) { //w innym przypadku...
10
+
$hitsnumber = $wpdb->get_results($wpdb->prepare("SELECT hit_count FROM $popular_posts_statistics_table WHERE post_id = %d", $postID), ARRAY_A);
11
11
$hitsnumber = $hitsnumber[0]['hit_count'];
12
-
$result = $wpdb->query("UPDATE $popular_posts_statistics_table SET hit_count = $hitsnumber + 1, date = NOW() WHERE post_id = $postID");
12
+
$wpdb->query($wpdb->prepare("UPDATE $popular_posts_statistics_table SET hit_count = %d + 1, date = NOW() WHERE post_id = %d", $hitsnumber, $postID));
13
13
}
14
14
}
15
15
@@ -19,17 +19,17 @@ function show_views($postID, $posnumber, $numberofdays, $ignoredpages) {
if ($wpdb->query("SELECT hit_count FROM $popular_posts_statistics_table")) {
22
-
$result = $wpdb->get_results("SELECT hit_count FROM $popular_posts_statistics_table WHERE date >= NOW() - INTERVAL $numberofdays DAY ORDER BY hit_count DESC", ARRAY_A);
23
-
$post_id_number = $wpdb->get_results("SELECT post_id FROM $popular_posts_statistics_table WHERE date >= NOW() - INTERVAL $numberofdays DAY ORDER BY hit_count DESC LIMIT $posnumber", ARRAY_A);
22
+
$result = $wpdb->get_results($wpdb->prepare("SELECT hit_count FROM $popular_posts_statistics_table WHERE date >= NOW() - INTERVAL %d DAY ORDER BY hit_count DESC", $numberofdays), ARRAY_A);
23
+
$post_id_number = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM $popular_posts_statistics_table WHERE date >= NOW() - INTERVAL %d DAY ORDER BY hit_count DESC LIMIT %d", $numberofdays, $posnumber), ARRAY_A);
$post_name_by_id = $wpdb->get_results("SELECT post_title FROM $posts_table WHERE ID = $post_number", ARRAY_A);
30
+
$post_name_by_id = $wpdb->get_results($wpdb->prepare("SELECT post_title FROM $posts_table WHERE ID = %d", $post_number), ARRAY_A);
31
31
if (!$post_name_by_id){ //sprawdza, czy post o danym ID istnieje, jeśli nie - kasuje rekord i przerywa skrypt (który by wyświetlał błąd w pierwszej linii)
32
-
$wpdb->query("DELETE FROM $popular_posts_statistics_table WHERE post_id = $post_number");
32
+
$wpdb->query($wpdb->prepare("DELETE FROM $popular_posts_statistics_table WHERE post_id = %d", $post_number));
33
33
break;
34
34
}
35
35
if (in_array($post_number, $ignoredpages)) { //sprawdza, czy postu nie ma na liście banów
0 commit comments