Fix bugs
This commit is contained in:
@@ -22,7 +22,9 @@ class CHECKER_SHORTCODE extends SHEET_DATA_CHECKER_PRO {
|
||||
public function __construct() {
|
||||
|
||||
// Load security class
|
||||
require_once SHEET_CHECKER_PRO_PATH . 'includes/class-Security.php';
|
||||
if (!class_exists('CHECKER_SECURITY')) {
|
||||
require_once SHEET_CHECKER_PRO_PATH . 'includes/class-Security.php';
|
||||
}
|
||||
|
||||
add_shortcode('checker', [$this, 'content'] );
|
||||
add_action( 'wp_enqueue_scripts', [$this, 'enqueue'] );
|
||||
@@ -101,13 +103,8 @@ class CHECKER_SHORTCODE extends SHEET_DATA_CHECKER_PRO {
|
||||
// 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);
|
||||
}
|
||||
// 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'];
|
||||
@@ -246,6 +243,58 @@ class CHECKER_SHORTCODE extends SHEET_DATA_CHECKER_PRO {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'];
|
||||
@@ -295,13 +344,8 @@ class CHECKER_SHORTCODE extends SHEET_DATA_CHECKER_PRO {
|
||||
// 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);
|
||||
}
|
||||
// Use WordPress HTTP API instead of fopen for better server compatibility
|
||||
$data = $this->fetch_remote_csv_data($url, $delimiter);
|
||||
|
||||
$validator = $_REQUEST['validate'];
|
||||
$validation = [];
|
||||
@@ -380,21 +424,8 @@ class CHECKER_SHORTCODE extends SHEET_DATA_CHECKER_PRO {
|
||||
$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);
|
||||
}
|
||||
// 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),
|
||||
|
||||
Reference in New Issue
Block a user