File "ajax.php"
Full Path: /home/ozbarhaber/public_html/19052025___siteeee/wp-content/themes/anka/lib/functions/ajax.php
File size: 1.92 KB
MIME-type: text/x-php
Charset: utf-8
<?php if(!defined('ABSPATH')) exit; ?>
<?php
// Clock
add_action("wp_ajax_safirClock", "safirClock");
add_action("wp_ajax_nopriv_safirClock", "safirClock");
function safirClock() {
if ( !wp_verify_nonce( $_REQUEST['nonce'], "safir_ajax_nonce")) {
exit("HATA.");
}
$result = array();
$result['time'] = time() * 1000;
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$result = json_encode($result);
echo $result;
}
else {
header("Location: ".$_SERVER["HTTP_REFERER"]);
}
die();
}
// Hits
add_action("wp_ajax_safirHits", "safirHits");
add_action("wp_ajax_nopriv_safirHits", "safirHits");
function safirHits() {
if ( !wp_verify_nonce( $_REQUEST['nonce'], "safir_ajax_nonce")) {
exit("HATA.");
}
$id = $_POST['id'];
$postHit = get_post_meta($id, 'hit', true);
if ($postHit == NULL) { $postHit = 0; }
$postHit++;
update_post_meta($id, 'hit', $postHit);
$result = array();
$result['data'] = $postHit;
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$result = json_encode($result);
echo $result;
}
else {
header("Location: ".$_SERVER["HTTP_REFERER"]);
}
die();
}
add_action("wp_ajax_safirGetHits", "safirGetHits");
add_action("wp_ajax_nopriv_safirGetHits", "safirGetHits");
function safirGetHits() {
if ( !wp_verify_nonce( $_REQUEST['nonce'], "safir_ajax_nonce")) {
exit("HATA.");
}
$ids = $_POST['ids'];
$hits = [];
foreach($ids as $id) {
if(is_numeric($id)) {
$hit = get_post_meta($id, "hit", true);
if ($hit == NULL) { $hit = 0; }
$hits[$id] = $hit;
}
}
$result = array();
$result['data'] = $hits;
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$result = json_encode($result);
echo $result;
}
else {
header("Location: ".$_SERVER["HTTP_REFERER"]);
}
die();
}