XmlStreamReader
3 weeks ago
partner-discount-sdk
3 weeks ago
api.php
3 weeks ago
arraytoxml.php
3 weeks ago
chunk.php
3 weeks ago
config.php
2 years ago
download.php
3 weeks ago
error.php
3 weeks ago
handler.php
3 weeks ago
helper.php
3 weeks ago
input.php
3 weeks ago
nested.php
3 weeks ago
rapidaddon.php
3 weeks ago
render.php
3 weeks ago
session.php
9 months ago
upload.php
3 weeks ago
zip.php
10 years ago
error.php
85 lines
| 1 | <?php |
| 2 | |
| 3 | class PMXI_Error{ |
| 4 | |
| 5 | public $recordNumber; |
| 6 | |
| 7 | public function __construct($recordNumber = false) { |
| 8 | $this->recordNumber = $recordNumber; |
| 9 | } |
| 10 | |
| 11 | public function handle(){ |
| 12 | |
| 13 | $error = $this->getLastError(); |
| 14 | $trace = $this->trace(); |
| 15 | if($error && strpos($error['file'], 'functions.php') !== false){ |
| 16 | $wp_uploads = $this->getUploadsDir(); |
| 17 | $functions = 'in '.$wp_uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php:'.$error['line']; |
| 18 | $error['message'] = str_replace($functions, '', $error['message']); |
| 19 | $error['message'] = str_replace("\\n",'',$error['message']); |
| 20 | $errorParts = explode('Stack trace', $error['message']); |
| 21 | $error['message'] = $errorParts[0]; |
| 22 | $error['message'] .=' on line '.$error['line']; |
| 23 | $error['message'] = str_replace("\n",'',$error['message']); |
| 24 | $error['message'] = str_replace("Uncaught Error:", '', $error['message']); |
| 25 | $error['message'] = 'PHP Error: ' . $error['message']; |
| 26 | $error['message'] = str_replace(' ', ' ', $error['message']); |
| 27 | echo "[[ERROR]]"; |
| 28 | if($error['message'] == '') { |
| 29 | $error['message'] = __('An unknown error occurred', 'wp-all-import'); |
| 30 | } |
| 31 | $this->terminate(json_encode(array('error' => '<span class="error">'.$error['message'].' of the Functions Editor'.'</span>', 'line' => $error['line'], 'title' => __('PHP Error','wp-all-import')))); |
| 32 | } else if(strpos($error['file'], 'XMLWriter.php') !== false ) { |
| 33 | if(strpos($error['message'],'syntax error, unexpected') !== false) { |
| 34 | echo "[[ERROR]]"; |
| 35 | $this->terminate(json_encode(array('error'=>__('You probably forgot to close a quote', 'wp-all-import'),'title' => __('PHP Error','wp-all-import')))); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @return array |
| 42 | */ |
| 43 | protected function getLastError() |
| 44 | { |
| 45 | return error_get_last(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @return mixed |
| 50 | */ |
| 51 | protected function getUploadsDir() |
| 52 | { |
| 53 | return wp_upload_dir(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Hack to be able to test the class in isolation |
| 58 | * |
| 59 | * @param $message |
| 60 | */ |
| 61 | protected function terminate($message) |
| 62 | { |
| 63 | exit($message); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- JSON payload consumed by JS client. |
| 64 | } |
| 65 | |
| 66 | protected function trace(){ |
| 67 | $e = new Exception(); |
| 68 | return $e->getTraceAsString(); |
| 69 | // return debug_backtrace(); |
| 70 | } |
| 71 | |
| 72 | public function import_data_handler($errno, $errstr, $errfile, $errline) { |
| 73 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 74 | error_log('Found import exception: ' . $errstr . ' ' . $errno . ' ' . $errfile . ' ' . $errline . ' for record #' . $this->recordNumber); |
| 75 | // trigger_error('TEST'); |
| 76 | // throw new XmlImportException($errstr, $errno, 0, $errfile, $errline); |
| 77 | } |
| 78 | |
| 79 | public function parse_data_handler($errno, $errstr, $errfile, $errline) { |
| 80 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 81 | error_log('Found parse exception: ' . $errstr . ' ' . $errno . ' ' . $errfile . ' ' . $errline); |
| 82 | throw new XmlImportException(esc_html($errstr), intval($errno)); |
| 83 | } |
| 84 | } |
| 85 |