| @@ -1,14 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * E2pdf Debug Controller | |
| 5 | - * | |
| 6 | - * @copyright Copyright 2017 https://e2pdf.com | |
| 7 | - * @license GPL v2 | |
| 8 | - * @version 1 | |
| 9 | - * @link https://e2pdf.com | |
| 10 | - * @since 0.00.01 | |
| 4 | + * File: /controller/e2pdf-debug.php | |
| 5 | + * | |
| 6 | + * @package E2Pdf | |
| 7 | + * @license GPLv3 | |
| 8 | + * @link https://e2pdf.com | |
| 11 | 9 | */ |
| 12 | 10 | if (!defined('ABSPATH')) { |
| 13 | 11 | die('Access denied.'); |
| 14 | 12 | } |
| @@ -14,77 +12,145 @@ | ||
| 14 | 12 | } |
| 15 | 13 | |
| 16 | 14 | class Controller_E2pdf_Debug extends Helper_E2pdf_View { |
| 17 | 15 | |
| 18 | - /** | |
| 19 | - * @url admin.php?page=e2pdf-debug | |
| 20 | - */ | |
| 16 | + // url: admin.php?page=e2pdf-debug | |
| 21 | 17 | public function index_action() { |
| 18 | + if ($this->post->get('_wpnonce')) { | |
| 19 | + if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_debug')) { | |
| 20 | + if ($this->post->get('e2pdf_updated')) { | |
| 21 | + update_option('e2pdf_version', '1.00.00'); | |
| 22 | + $this->redirect( | |
| 23 | + $this->helper->get_url( | |
| 24 | + [ | |
| 25 | + 'page' => 'e2pdf-debug', | |
| 26 | + 'notification' => $this->add_notification('update', __('Success', 'e2pdf')), | |
| 27 | + ] | |
| 28 | + ) | |
| 29 | + ); | |
| 30 | + } | |
| 31 | + } else { | |
| 32 | + wp_die($this->message('wp_verify_nonce_error')); | |
| 33 | + } | |
| 34 | + } | |
| 35 | + $this->view('api', new Model_E2pdf_Api()); | |
| 36 | + if (ini_get('disable_functions')) { | |
| 37 | + $disabled_functions = explode(',', ini_get('disable_functions')); | |
| 38 | + } else { | |
| 39 | + $disabled_functions = []; | |
| 40 | + } | |
| 41 | + $this->view('disabled_functions', $disabled_functions); | |
| 42 | + } | |
| 22 | 43 | |
| 23 | - $this->view('debug', $this->get_debug()); | |
| 44 | + // url: admin.php?page=e2pdf-debug&action=db | |
| 45 | + public function db_action() { | |
| 46 | + global $wpdb; | |
| 47 | + if ($this->post->get('_wpnonce')) { | |
| 48 | + if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_debug')) { | |
| 49 | + if ($this->post->get('e2pdf_db_repair')) { | |
| 50 | + $db_prefix = $wpdb->prefix; | |
| 51 | + $this->helper->load('db')->db_repair($db_prefix); | |
| 52 | + } elseif ($this->post->get('e2pdf_db_repair_collate')) { | |
| 53 | + $db_prefix = $wpdb->prefix; | |
| 54 | + $this->helper->load('db')->db_repair_collate($db_prefix); | |
| 55 | + } elseif ($this->post->get('e2pdf_db')) { | |
| 56 | + $db_prefix = $wpdb->prefix; | |
| 57 | + $this->helper->load('db')->db_init($db_prefix); | |
| 58 | + } | |
| 59 | + $this->redirect( | |
| 60 | + $this->helper->get_url( | |
| 61 | + [ | |
| 62 | + 'page' => 'e2pdf-debug', | |
| 63 | + 'action' => 'db', | |
| 64 | + 'notification' => $this->add_notification('update', __('Success', 'e2pdf')), | |
| 65 | + ] | |
| 66 | + ) | |
| 67 | + ); | |
| 68 | + } else { | |
| 69 | + wp_die($this->message('wp_verify_nonce_error')); | |
| 70 | + } | |
| 71 | + } | |
| 72 | + $this->view('db_structure', $this->helper->load('db')->db_structure($wpdb->prefix, true)); | |
| 73 | + $this->view('db_check_collate', $this->helper->load('db')->db_check_collate($wpdb->prefix)); | |
| 24 | 74 | } |
| 25 | 75 | |
| 26 | - /** | |
| 27 | - * @url admin.php?page=e2pdf-debug&action=phpinfo | |
| 28 | - */ | |
| 76 | + // url: admin.php?page=e2pdf-debug&action=phpinfo | |
| 29 | 77 | public function phpinfo_action() { |
| 30 | - | |
| 31 | 78 | $this->view('phpinfo', $this->get_php_info()); |
| 32 | 79 | } |
| 33 | 80 | |
| 34 | - /** | |
| 35 | - * @url admin.php?page=e2pdf-debug&action=requests | |
| 36 | - */ | |
| 37 | - public function requests_action() { | |
| 81 | + // url: admin.php?page=e2pdf-debug&action=requests | |
| 82 | + public function connections_action() { | |
| 83 | + $connections = [ | |
| 84 | + 'self_connection' => [], | |
| 85 | + 'api_connection_upload' => [], | |
| 86 | + 'api_connection_download' => [], | |
| 87 | + ]; | |
| 38 | 88 | |
| 39 | - $this->view('requests', $this->get_requests()); | |
| 40 | - } | |
| 89 | + $url = plugins_url('img/loader.svg?v=' . time(), $this->helper->get('plugin_file_path')); | |
| 90 | + $image = $this->helper->load('image')->get_by_url($url); | |
| 91 | + if ($image !== '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0" width="20px" height="20px" viewBox="0 0 128 128" xml:space="preserve"><g><path d="M63.9.45A63.46 63.46 0 1 1 .47 63.9 63.46 63.46 0 0 1 63.9.46zM41.8 19.38a22.27 22.27 0 1 1-22.3 22.27 22.27 22.27 0 0 1 22.27-22.27z" fill="#808080" fill-rule="evenodd"/><animateTransform attributeName="transform" type="rotate" from="0 64 64" to="360 64 64" dur="960ms" repeatCount="indefinite"></animateTransform></g></svg>') { | |
| 92 | + $connections['self_connection'] = [ | |
| 93 | + 'error' => '', | |
| 94 | + ]; | |
| 95 | + } | |
| 41 | 96 | |
| 42 | - /** | |
| 43 | - * Get debug model | |
| 44 | - * | |
| 45 | - * @return object - Debug model | |
| 46 | - */ | |
| 47 | - public function get_debug() { | |
| 97 | + $file = 10000000; | |
| 98 | + $times = []; | |
| 99 | + $times[] = microtime(true); | |
| 100 | + $model_e2pdf_api = new Model_E2pdf_Api(); | |
| 101 | + $model_e2pdf_api->set( | |
| 102 | + [ | |
| 103 | + 'action' => 'common/connection', | |
| 104 | + 'data' => [ | |
| 105 | + 'upload' => str_repeat(' ', $file), | |
| 106 | + ], | |
| 107 | + ] | |
| 108 | + ); | |
| 109 | + $request = $model_e2pdf_api->request(); | |
| 110 | + $times[] = microtime(true); | |
| 111 | + if (isset($request['error'])) { | |
| 112 | + $connections['api_connection_upload'] = [ | |
| 113 | + 'error' => $request['error'], | |
| 114 | + 'result' => '', | |
| 115 | + ]; | |
| 116 | + } else { | |
| 117 | + $connections['api_connection_upload'] = [ | |
| 118 | + 'result' => $this->helper->load('convert')->from_bytes($file / ($times[1] - $times[0])) . '/s (' . $this->helper->load('convert')->from_bytes($file) . ' in ' . number_format(($times[1] - $times[0]), 2) . 's)', | |
| 119 | + ]; | |
| 120 | + } | |
| 48 | 121 | |
| 49 | - $model_e2pdf_debug = new Model_E2pdf_Debug(); | |
| 50 | - return $model_e2pdf_debug; | |
| 122 | + $times[] = microtime(true); | |
| 123 | + $model_e2pdf_api = new Model_E2pdf_Api(); | |
| 124 | + $model_e2pdf_api->set( | |
| 125 | + [ | |
| 126 | + 'action' => 'common/connection', | |
| 127 | + 'data' => [ | |
| 128 | + 'download' => true, | |
| 129 | + ], | |
| 130 | + ] | |
| 131 | + ); | |
| 132 | + $request = $model_e2pdf_api->request(); | |
| 133 | + $times[] = microtime(true); | |
| 134 | + if (isset($request['error'])) { | |
| 135 | + $connections['api_connection_download'] = [ | |
| 136 | + 'error' => $request['error'], | |
| 137 | + 'result' => '', | |
| 138 | + ]; | |
| 139 | + } else { | |
| 140 | + $connections['api_connection_download'] = [ | |
| 141 | + 'result' => $this->helper->load('convert')->from_bytes($file / ($times[3] - $times[2])) . '/s (' . $this->helper->load('convert')->from_bytes($file) . ' in ' . number_format(($times[3] - $times[2]), 2) . 's)', | |
| 142 | + ]; | |
| 143 | + } | |
| 144 | + $this->view('connections', $connections); | |
| 51 | 145 | } |
| 52 | 146 | |
| 53 | - /** | |
| 54 | - * Get phpinfo | |
| 55 | - * | |
| 56 | - * @return string - PHP Info | |
| 57 | - */ | |
| 147 | + // php info | |
| 58 | 148 | public function get_php_info() { |
| 59 | - | |
| 60 | 149 | ob_start(); |
| 61 | 150 | phpinfo(); |
| 62 | 151 | $contents = ob_get_contents(); |
| 63 | 152 | ob_end_clean(); |
| 64 | - $php_info = (str_replace("module_Zend Optimizer", "module_Zend_Optimizer", preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $contents))); | |
| 153 | + $php_info = (str_replace('module_Zend Optimizer', 'module_Zend_Optimizer', preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $contents))); | |
| 65 | 154 | return $php_info; |
| 66 | 155 | } |
| 67 | - | |
| 68 | - /** | |
| 69 | - * Get phpinfo | |
| 70 | - * | |
| 71 | - * @return string | |
| 72 | - */ | |
| 73 | - public function get_requests() { | |
| 74 | - | |
| 75 | - $model_e2pdf_api = new Model_E2pdf_Api(); | |
| 76 | - | |
| 77 | - $requests = ""; | |
| 78 | - | |
| 79 | - $requests .= '<strong>common/debug</strong>'; | |
| 80 | - $model_e2pdf_api->set(array( | |
| 81 | - 'action' => 'common/debug', | |
| 82 | - )); | |
| 83 | - $requests .= '<pre>'; | |
| 84 | - $requests .= print_r($model_e2pdf_api->request(), true); | |
| 85 | - $requests .= '</pre>'; | |
| 86 | - | |
| 87 | - return $requests; | |
| 88 | - } | |
| 89 | - | |
| 90 | 156 | } |