'',
'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
// Use WordPress HTTP API instead of fopen for better server compatibility
$data = $this->fetch_remote_csv_data($url, $delimiter);
$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;
}
/**
* Fetch remote CSV/TSV data using WordPress HTTP API
* Replaces fopen() for better server compatibility
*/
private function fetch_remote_csv_data($url, $delimiter, $limit = null) {
$data = [];
// Use WordPress HTTP API to fetch remote file
$response = wp_remote_get($url);
if (is_wp_error($response)) {
error_log('Failed to fetch remote file: ' . $response->get_error_message());
return $data;
}
$body = wp_remote_retrieve_body($response);
if (empty($body)) {
error_log('Empty response from remote file: ' . $url);
return $data;
}
// Parse CSV/TSV data
$lines = explode("\n", $body);
if (empty($lines)) {
return $data;
}
// Get headers from first line
$keys = str_getcsv($lines[0], $delimiter);
// Process data rows
$count = 0;
for ($i = 1; $i < count($lines); $i++) {
if (empty(trim($lines[$i]))) {
continue; // Skip empty lines
}
$row = str_getcsv($lines[$i], $delimiter);
if (count($keys) === count($row)) {
$data[] = array_combine($keys, $row);
$count++;
// Apply limit if specified
if ($limit && $count >= $limit) {
break;
}
}
}
return $data;
}
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
// Use WordPress HTTP API instead of fopen for better server compatibility
$data = $this->fetch_remote_csv_data($url, $delimiter);
$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" : ",";
// Use WordPress HTTP API instead of fopen for better server compatibility
$data = $this->fetch_remote_csv_data($url, $delimiter, $limit);
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'
]);
}
}