function akpc_api_record_view($id = null) { global $wpdb; $akpc = new ak_popularity_contest(); $akpc->get_settings(); $ids = array(); if ($id) { $ids[] = $id; } else { foreach (explode(',', $_POST['ids']) as $id) { if ($id = intval($id)) { $ids[] = $id; } } } array_unique($ids); if (!empty($_GET['type'])) { $type = $_GET['type']; $response = 'img'; } else { $type = $_POST['type']; $response = 'json'; } if (count($ids) && $akpc->record_view(true, $ids, $type)) { $json = '{"result":true,"ids":"' . implode(',', $ids) . '","type":"' . sanitize_title($type) . '"}'; } else { $json = '{"result":false,"ids":"' . implode(',', $ids) . '","type":"' . sanitize_title($type) . '"}'; } switch ($response) { case 'img': header('Content-type: image/jpeg'); break; case 'json': header('Content-type: application/json'); echo $json; break; } exit; }