'',
'description' => '',
'card' => [
'width' => 500,
'background' => '#cccccc',
'bg_opacity' => 50,
'border_radius' => 1,
'box_shadow' => '10px 5px 15px -5px',
'box_shadow_color' => '#333333',
'title' => '#333333',
'title_align' => 'left',
'description' => '#333333',
'description_align' => 'left',
'divider' => '#333333',
'divider_width' => 1
],
'field' => [
'label' => 'block',
'label-color' => '#333333'
],
'fields' => [],
'search_button' => [
'text' => 'Search',
'bg_color' => '#cccccc',
'text_color' => '#333333',
'position' => 'flex-end'
],
'back_button' => [
'text' => 'Back',
'bg_color' => '#cccccc',
'text_color' => '#333333',
'position' => 'flex-start'
],
'result' => [
'display' => 'vertical-tabel',
'header' => '#333333',
'value' => '#333333',
'columns' => [],
'border_width' => 1
]
] );
$url = $checker['link'];
$link_format = substr($url, -3);
// Set the delimiter based on the format
$delimiter = $link_format == 'tsv' ? "\t" : ","; // Use tab for TSV, comma for CSV
if (($handle = fopen($url, "r")) !== false) {
$keys = fgetcsv($handle, 0, $delimiter); // Read the first row as keys
while (($row = fgetcsv($handle, 0, $delimiter)) !== false) {
$data[] = array_combine($keys, $row); // Combine keys with row values and add to the data array
}
fclose($handle);
}
$background_color = $checker['card']['background'];
if($checker['card']['bg_opacity'] < 100){
$background_color = $checker['card']['background'].''.$checker['card']['bg_opacity'];
}
$render = '';
$render .= '
';
$render .= '
';
$render .= '
';
$render .= '
';
$render .= '
';
$render .= '
';
$render .= '
';
$render .= '
';
$render .= '
';
$render .= '';
$render .= '
';
$render .= '
';
$render .= '
';
$render .= '';
// Pass settings to frontend as data attributes
$render .= '';
return $render;
}
public function checker_public_validation() {
$post_id = $_REQUEST['checker_id'];
$checker = get_post_meta( $post_id, 'checker', true );
// Security checks
$ip = CHECKER_SECURITY::get_client_ip();
// Check rate limit
$rate_limit = CHECKER_SECURITY::check_rate_limit($post_id, $ip);
if (!$rate_limit['allowed']) {
wp_send_json_error([
'message' => $rate_limit['message'],
'type' => 'rate_limit'
]);
return;
}
// Check reCAPTCHA if enabled
if (isset($_REQUEST['recaptcha_token'])) {
$recaptcha = CHECKER_SECURITY::verify_recaptcha($post_id, $_REQUEST['recaptcha_token']);
if (!$recaptcha['success']) {
wp_send_json_error([
'message' => $recaptcha['message'],
'type' => 'recaptcha'
]);
return;
}
}
// Check Turnstile if enabled
if (isset($_REQUEST['turnstile_token'])) {
$turnstile = CHECKER_SECURITY::verify_turnstile($post_id, $_REQUEST['turnstile_token']);
if (!$turnstile['success']) {
wp_send_json_error([
'message' => $turnstile['message'],
'type' => 'turnstile'
]);
return;
}
}
$url = $checker['link'];
$link_format = substr($url, -3);
// Set the delimiter based on the format
$delimiter = $link_format == 'tsv' ? "\t" : ","; // Use tab for TSV, comma for CSV
if (($handle = fopen($url, "r")) !== false) {
$keys = fgetcsv($handle, 0, $delimiter); // Read the first row as keys
while (($row = fgetcsv($handle, 0, $delimiter)) !== false) {
$data[] = array_combine($keys, $row); // Combine keys with row values and add to the data array
}
fclose($handle);
}
$validator = $_REQUEST['validate'];
$validation = [];
foreach($validator as $validate){
$validation[$validate['kolom']] = $validate['value'];
}
$validator_count = count($validator);
$result = [];
if(!empty($data)){
foreach($data as $row){
$valid = [];
foreach($row as $header => $value){
$id = '_'.strtolower(str_replace(' ', '_', $header));
$include = false;
if(isset($validation[$header])){
if($checker['fields'][$id]['match'] == 'match' && strtolower($value) == strtolower($validation[$header])){
$include = true;
}
if($checker['fields'][$id]['match'] == 'contain' && false !== strpos(strtolower($value), strtolower($validation[$header]))){
$include = true;
}
if($include){
$valid[$header] = $value;
}
}
}
if($validator_count !== count($valid)){
continue;
}
$result[] = $row;
}
}
$send = [
'count' => count($result),
'rows' => $result,
'settings' => $checker['result'],
'output' => $checker['output']
];
wp_send_json($send);
}
/**
* Load all data from sheet (for show all mode)
*/
public function checker_load_all_data() {
$post_id = isset($_REQUEST['checker_id']) ? intval($_REQUEST['checker_id']) : 0;
$limit = isset($_REQUEST['limit']) ? intval($_REQUEST['limit']) : 100;
if (!$post_id) {
wp_send_json_error(['message' => 'Invalid checker ID']);
return;
}
$checker = get_post_meta($post_id, 'checker', true);
if (!$checker || !isset($checker['link'])) {
wp_send_json_error(['message' => 'Checker not found']);
return;
}
// Security check - rate limiting only
$ip = CHECKER_SECURITY::get_client_ip();
$rate_limit = CHECKER_SECURITY::check_rate_limit($post_id, $ip);
if (!$rate_limit['allowed']) {
wp_send_json_error([
'message' => $rate_limit['message'],
'type' => 'rate_limit'
]);
return;
}
$url = $checker['link'];
$link_format = substr($url, -3);
$delimiter = $link_format == 'tsv' ? "\t" : ",";
$data = [];
$handle = fopen($url, "r");
if ($handle !== false) {
$keys = fgetcsv($handle, 0, $delimiter);
$count = 0;
while (($row = fgetcsv($handle, 0, $delimiter)) !== false && $count < $limit) {
if (count($keys) === count($row)) {
$data[] = array_combine($keys, $row);
$count++;
}
}
fclose($handle);
}
wp_send_json([
'count' => count($data),
'rows' => $data,
'settings' => $checker['result'],
'output' => $checker['output'],
'url_params' => $checker['url_params'] ?? [],
'filter_mode' => $checker['result']['filter_mode'] ?? 'search'
]);
}
}