Changeset 3339065
- Timestamp:
- 08/04/2025 02:13:41 PM (8 months ago)
- Location:
- recruitly/trunk
- Files:
-
- 3 edited
-
admin/dataloader.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
-
recruitly.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
recruitly/trunk/admin/dataloader.php
r3338991 r3339065 710 710 // Check for JSON errors 711 711 if (json_last_error() !== JSON_ERROR_NONE) { 712 recruitly_log_exception(new Exception('JSON decode error in sync_post_type_single: ' . json_last_error_msg())); 712 $sample = substr($curlResp, 0, 1000); 713 $error_msg = 'JSON decode error in sync_post_type_single: ' . json_last_error_msg() . '. Response sample: ' . $sample; 714 715 // Print to screen for debugging 716 echo '<div style="background: red; color: white; padding: 20px; margin: 20px; border: 2px solid black; position: relative; z-index: 999999;">'; 717 echo '<h2>RECRUITLY JSON ERROR (Single Job)</h2>'; 718 echo '<p><strong>Error:</strong> ' . esc_html(json_last_error_msg()) . '</p>'; 719 echo '<p><strong>Job ID:</strong> ' . esc_html($jobId) . '</p>'; 720 echo '<p><strong>API URL:</strong> ' . esc_html($apiUrl) . '</p>'; 721 echo '<p><strong>Raw Response (first 1000 chars):</strong></p>'; 722 echo '<pre style="background: black; color: lime; padding: 10px; overflow: auto;">' . esc_html($sample) . '</pre>'; 723 echo '<p><strong>Response Length:</strong> ' . strlen($curlResp) . ' characters</p>'; 724 echo '</div>'; 725 726 recruitly_log_exception(new Exception($error_msg)); 713 727 return; 714 728 } … … 812 826 $responseBody = wp_remote_retrieve_body($response); 813 827 828 // Store original for debugging 829 $originalResponse = $responseBody; 830 831 // Check if response is empty 832 if (empty($responseBody)) { 833 recruitly_log_exception(new Exception('Empty response from API in get_total_jobs_count')); 834 return 0; 835 } 836 814 837 // Remove BOM if present 815 838 $responseBody = preg_replace('/^\xEF\xBB\xBF/', '', $responseBody); 839 840 // Try multiple methods to extract JSON from the response 841 // Method 1: Look for JSON object pattern { ... } 842 if (preg_match('/\{[^{}]*"count"\s*:\s*\d+[^{}]*\}/s', $responseBody, $matches)) { 843 $responseBody = $matches[0]; 844 } 845 // Method 2: More aggressive JSON extraction 846 else if (preg_match('/(\{(?:[^{}]|(?R))*\})/s', $responseBody, $matches)) { 847 // This regex recursively matches balanced braces 848 foreach ($matches as $match) { 849 if (strpos($match, '"count"') !== false) { 850 $responseBody = $match; 851 break; 852 } 853 } 854 } 855 // Method 3: Simple extraction between first { and last } 856 else { 857 // Trim any whitespace or non-JSON content 858 $responseBody = trim($responseBody); 859 860 // Remove any content before the first { and after the last } 861 $start = strpos($responseBody, '{'); 862 $end = strrpos($responseBody, '}'); 863 if ($start !== false && $end !== false && $end > $start) { 864 $responseBody = substr($responseBody, $start, $end - $start + 1); 865 } 866 } 867 868 // Additional cleanup: remove PHP warnings/notices if present 869 // These often appear as "Notice: ..." or "Warning: ..." before the JSON 870 $responseBody = preg_replace('/^(?:Notice|Warning|Error|Fatal error|Parse error):.*?\n/m', '', $responseBody); 871 // Remove any HTML comments 872 $responseBody = preg_replace('/<!--.*?-->/s', '', $responseBody); 873 // Remove any script tags that might have been injected 874 $responseBody = preg_replace('/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/s', '', $responseBody); 816 875 817 876 // Fix any encoding issues 818 877 if (function_exists('mb_check_encoding') && !mb_check_encoding($responseBody, 'UTF-8')) { 819 878 $responseBody = mb_convert_encoding($responseBody, 'UTF-8', 'UTF-8'); 879 } 880 881 // Check if response looks like HTML error page instead of JSON 882 if (strpos($responseBody, '<!DOCTYPE') !== false || strpos($responseBody, '<html') !== false) { 883 recruitly_log_exception(new Exception('API returned HTML instead of JSON in get_total_jobs_count. First 500 chars: ' . substr($responseBody, 0, 500))); 884 return 0; 820 885 } 821 886 … … 830 895 // Check for JSON errors 831 896 if (json_last_error() !== JSON_ERROR_NONE) { 832 recruitly_log_exception(new Exception('JSON decode error in get_total_jobs_count: ' . json_last_error_msg())); 897 // Try one more aggressive extraction as last resort 898 if (preg_match('/"count"\s*:\s*(\d+)/', $originalResponse, $countMatch)) { 899 // Found count value directly, construct minimal valid JSON 900 $fallbackJson = '{"count":' . $countMatch[1] . ',"success":true}'; 901 $restResponse = json_decode($fallbackJson); 902 if (json_last_error() === JSON_ERROR_NONE && isset($restResponse->count)) { 903 // Log that we recovered using fallback 904 recruitly_log_exception(new Exception('Used fallback JSON extraction for count API. Original response had issues.')); 905 return (int)$restResponse->count; 906 } 907 } 908 909 // Log more details about what was received 910 $sample = substr($responseBody, 0, 1000); // First 1000 chars for debugging 911 $originalSample = substr($originalResponse, 0, 1000); // Original response for comparison 912 $error_msg = 'JSON decode error in get_total_jobs_count: ' . json_last_error_msg() . '. Response sample: ' . $sample; 913 914 // Print to screen for debugging 915 echo '<div style="background: red; color: white; padding: 20px; margin: 20px; border: 2px solid black; position: relative; z-index: 999999;">'; 916 echo '<h2>RECRUITLY JSON ERROR (Count API)</h2>'; 917 echo '<p><strong>Error:</strong> ' . esc_html(json_last_error_msg()) . '</p>'; 918 echo '<p><strong>API URL:</strong> ' . esc_html($apiUrl) . '</p>'; 919 920 // Show original response 921 echo '<p><strong>ORIGINAL Response (first 1000 chars):</strong></p>'; 922 echo '<pre style="background: #330000; color: yellow; padding: 10px; overflow: auto; max-height: 200px;">' . esc_html($originalSample) . '</pre>'; 923 924 // Show cleaned response 925 echo '<p><strong>CLEANED Response (first 1000 chars):</strong></p>'; 926 echo '<pre style="background: black; color: lime; padding: 10px; overflow: auto; max-height: 200px;">' . esc_html($sample) . '</pre>'; 927 928 // Show what changed 929 if ($originalResponse !== $responseBody) { 930 echo '<p style="background: yellow; color: black; padding: 10px;"><strong>NOTE:</strong> Response was modified during cleanup. Original length: ' . strlen($originalResponse) . ', Cleaned length: ' . strlen($responseBody) . '</p>'; 931 } 932 933 echo '<p><strong>Response Length:</strong> Original: ' . strlen($originalResponse) . ' | Cleaned: ' . strlen($responseBody) . ' characters</p>'; 934 echo '<p><strong>PHP Version:</strong> ' . phpversion() . '</p>'; 935 936 // Try to show what's before/after the JSON if visible 937 $jsonStart = strpos($originalResponse, '{'); 938 if ($jsonStart > 0) { 939 echo '<p style="background: orange; color: black; padding: 10px;"><strong>Content before JSON:</strong> ' . esc_html(substr($originalResponse, 0, min($jsonStart, 100))) . '</p>'; 940 } 941 942 echo '</div>'; 943 944 // Also log it 945 recruitly_log_exception(new Exception($error_msg)); 833 946 return 0; 834 947 } … … 872 985 { 873 986 try { 987 // Debug output at start of sync 988 echo '<div style="background: green; color: white; padding: 10px; margin: 10px; border: 1px solid black;">'; 989 echo '<h3>RECRUITLY SYNC STARTING</h3>'; 990 echo '<p><strong>API Server:</strong> ' . esc_html($apiServer) . '</p>'; 991 echo '<p><strong>Time:</strong> ' . date('Y-m-d H:i:s') . '</p>'; 992 echo '</div>'; 993 874 994 $totalJobsCount = recruitly_wordpress_get_total_jobs_count($apiKey, $apiServer); 875 995 876 996 if ($totalJobsCount <= 0) { 997 echo '<div style="background: yellow; color: black; padding: 10px; margin: 10px;">'; 998 echo '<strong>No jobs found or error getting count. Truncating post type.</strong>'; 999 echo '</div>'; 877 1000 recruitly_wordpress_truncate_post_type(); 878 1001 return; 879 1002 } 1003 1004 echo '<div style="background: green; color: white; padding: 10px; margin: 10px;">'; 1005 echo '<strong>Total Jobs from API:</strong> ' . $totalJobsCount; 1006 echo '</div>'; 880 1007 881 1008 $totalJobsInLocal = recruitly_wordpress_count_post_type_all(); … … 926 1053 $responseBody = wp_remote_retrieve_body($response); 927 1054 1055 // Store original for debugging 1056 $originalResponse = $responseBody; 1057 1058 // Debug output for ALL responses during development 1059 if (defined('WP_DEBUG') && WP_DEBUG) { 1060 echo '<div style="background: blue; color: white; padding: 10px; margin: 10px; border: 1px solid black;">'; 1061 echo '<strong>Page ' . $pageNumber . ' Response (first 200 chars):</strong> '; 1062 echo '<pre>' . esc_html(substr($responseBody, 0, 200)) . '</pre>'; 1063 echo '</div>'; 1064 } 1065 1066 // Check for empty response 1067 if (empty($responseBody)) { 1068 echo '<div style="background: orange; color: black; padding: 20px; margin: 20px; border: 2px solid black;">'; 1069 echo '<h2>RECRUITLY EMPTY RESPONSE</h2>'; 1070 echo '<p><strong>Page Number:</strong> ' . esc_html($pageNumber) . '</p>'; 1071 echo '<p><strong>API URL:</strong> ' . esc_html($apiUrl) . '</p>'; 1072 echo '<p><strong>HTTP Status:</strong> ' . wp_remote_retrieve_response_code($response) . '</p>'; 1073 echo '</div>'; 1074 continue; 1075 } 1076 928 1077 // Clean up JSON before parsing 929 1078 // Remove BOM if present 930 1079 $responseBody = preg_replace('/^\xEF\xBB\xBF/', '', $responseBody); 1080 1081 // Additional cleanup: remove PHP warnings/notices if present 1082 $responseBody = preg_replace('/^(?:Notice|Warning|Error|Fatal error|Parse error):.*?\n/m', '', $responseBody); 1083 // Remove any HTML comments 1084 $responseBody = preg_replace('/<!--.*?-->/s', '', $responseBody); 1085 // Remove any script tags 1086 $responseBody = preg_replace('/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/s', '', $responseBody); 931 1087 932 1088 // Fix any encoding issues … … 945 1101 // Check for JSON errors 946 1102 if (json_last_error() !== JSON_ERROR_NONE) { 947 recruitly_log_exception(new Exception('JSON decode error in sync_post_type: ' . json_last_error_msg())); 1103 $sample = substr($responseBody, 0, 1000); 1104 $originalSample = substr($originalResponse, 0, 1000); 1105 $error_msg = 'JSON decode error in sync_post_type: ' . json_last_error_msg() . '. Response sample: ' . $sample; 1106 1107 // Print to screen for debugging 1108 echo '<div style="background: red; color: white; padding: 20px; margin: 20px; border: 2px solid black; position: relative; z-index: 999999;">'; 1109 echo '<h2>RECRUITLY JSON ERROR (Job List - Page ' . $pageNumber . ')</h2>'; 1110 echo '<p><strong>Error:</strong> ' . esc_html(json_last_error_msg()) . '</p>'; 1111 echo '<p><strong>API URL:</strong> ' . esc_html($apiUrl) . '</p>'; 1112 1113 // Show original response 1114 echo '<p><strong>ORIGINAL Response (first 1000 chars):</strong></p>'; 1115 echo '<pre style="background: #330000; color: yellow; padding: 10px; overflow: auto; max-height: 200px;">' . esc_html($originalSample) . '</pre>'; 1116 1117 // Show cleaned response 1118 echo '<p><strong>CLEANED Response (first 1000 chars):</strong></p>'; 1119 echo '<pre style="background: black; color: lime; padding: 10px; overflow: auto; max-height: 200px;">' . esc_html($sample) . '</pre>'; 1120 1121 // Show what changed 1122 if ($originalResponse !== $responseBody) { 1123 echo '<p style="background: yellow; color: black; padding: 10px;"><strong>NOTE:</strong> Response was modified during cleanup. Original length: ' . strlen($originalResponse) . ', Cleaned length: ' . strlen($responseBody) . '</p>'; 1124 1125 // Try to show what's before the JSON 1126 $jsonStart = strpos($originalResponse, '{'); 1127 if ($jsonStart > 0) { 1128 echo '<p style="background: orange; color: black; padding: 10px;"><strong>Content before JSON:</strong> ' . esc_html(substr($originalResponse, 0, min($jsonStart, 200))) . '</p>'; 1129 } 1130 } 1131 1132 echo '<p><strong>Response Length:</strong> Original: ' . strlen($originalResponse) . ' | Cleaned: ' . strlen($responseBody) . ' characters</p>'; 1133 echo '</div>'; 1134 1135 recruitly_log_exception(new Exception($error_msg)); 948 1136 continue; 949 1137 } -
recruitly/trunk/readme.txt
r3339001 r3339065 4 4 Requires at least: 4.5 5 5 Tested up to: 6.8.2 6 Stable tag: 2.0.3 26 Stable tag: 2.0.33 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 137 137 * Fix character encoding issues. 138 138 139 = 2.0.33 = 140 * Fix character encoding issues. 141 139 142 == Upgrade Notice == 140 143 -
recruitly/trunk/recruitly.php
r3338999 r3339065 4 4 Plugin URI: https://recruitly.io 5 5 Description: Recruitly job board integration. 6 Version: 2.0.3 26 Version: 2.0.33 7 7 Author: Recruitly 8 8 Author URI: https://recruitly.io … … 15 15 exit; // Exit if accessed directly 16 16 } 17 define('RECRUITLY_PLUGIN_VERSION', '2.0.3 2');17 define('RECRUITLY_PLUGIN_VERSION', '2.0.33'); 18 18 19 19 defined('RECRUITLY_POST_TYPE') or define('RECRUITLY_POST_TYPE', 'current-vacancies');
Note: See TracChangeset
for help on using the changeset viewer.