PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.2.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.2.0
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
← All changes | classes/Visualizer/Source/Query.php +32 -82 3.10.13.2.0 View file →
@@ -35,35 +35,15 @@
35 35 */
36 36 protected $_query;
37 37
38 38 /**
39 - * The chart id.
40 - *
41 - * @access protected
42 - * @var int
43 - */
44 - protected $_chart_id;
45 -
46 - /**
47 - * Any additional parameters (e.g. for connecting to a remote db).
48 - *
49 - * @access protected
50 - * @var array
51 - */
52 - protected $_params;
53 -
54 - /**
55 39 * Constructor.
56 40 *
57 41 * @access public
58 42 * @param string $query The query.
59 - * @param int $chart_id The chart id.
60 - * @param array $params Any additional parameters (e.g. for connecting to a remote db).
61 43 */
62 - public function __construct( $query = null, $chart_id = null, $params = null ) {
44 + public function __construct( $query = null ) {
63 45 $this->_query = $query;
64 - $this->_chart_id = $chart_id;
65 - $this->_params = $params;
66 46 }
67 47
68 48 /**
69 49 * Fetches information from source, parses it and builds series and data arrays.
@@ -78,83 +58,52 @@
78 58 if ( empty( $this->_query ) ) {
79 59 return false;
80 60 }
81 61
82 - // only select queries allowed.
83 - if ( preg_match( '/^\s*(insert|delete|update|replace|create|alter|drop|truncate)\s/i', $this->_query ) ) {
84 - $this->_error = __( 'Only SELECT queries are allowed', 'visualizer' );
85 - return false;
86 - }
87 -
88 62 // impose a limit if no limit clause is provided.
89 63 if ( strpos( strtolower( $this->_query ), ' limit ' ) === false ) {
90 - $this->_query .= ' LIMIT ' . apply_filters( 'visualizer_sql_query_limit', 1000, $this->_chart_id );
64 + $this->_query .= ' LIMIT ' . apply_filters( 'visualizer_sql_query_limit', 1000 );
91 65 }
92 66
93 - $this->_query = apply_filters( 'visualizer_db_query', $this->_query, $this->_chart_id, $this->_params );
67 + global $wpdb;
68 + $wpdb->hide_errors();
69 + // @codingStandardsIgnoreStart
70 + $rows = $wpdb->get_results( $this->_query, $results_as_numeric_array ? ARRAY_N : ARRAY_A );
71 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Firing query %s to get results %s with error %s', $this->_query, print_r( $rows, true ), print_r( $wpdb->last_error, true ) ), 'debug', __FILE__, __LINE__ );
72 + // @codingStandardsIgnoreEnd
73 + $wpdb->show_errors();
94 74
95 - $results = array();
96 - $headers = array();
97 -
98 - // short circuit results for remote dbs.
99 - if ( false !== ( $remote_results = apply_filters( 'visualizer_db_query_execute', false, $this->_query, $as_html, $results_as_numeric_array, $raw_results, $this->_chart_id, $this->_params ) ) ) {
100 - $error = $remote_results['error'];
101 - if ( empty( $error ) ) {
102 - $results = $remote_results['results'];
103 - $headers = $remote_results['headers'];
104 - }
105 -
106 - $this->_error = $error;
107 -
108 - if ( $raw_results ) {
109 - return $results;
110 - }
75 + if ( $raw_results ) {
76 + return $rows;
111 77 }
112 78
113 - if ( ! ( $results && $headers ) ) {
114 - global $wpdb;
115 - $wpdb->hide_errors();
116 - // @codingStandardsIgnoreStart
117 - $rows = $wpdb->get_results( $this->_query, $results_as_numeric_array ? ARRAY_N : ARRAY_A );
118 - // @codingStandardsIgnoreEnd
119 - $wpdb->show_errors();
120 -
121 - if ( $raw_results ) {
122 - return $rows;
123 - }
124 -
79 + if ( $rows ) {
80 + $results = array();
81 + $headers = array();
125 82 if ( $rows ) {
126 - $results = array();
127 - $headers = array();
128 - if ( $rows ) {
129 - $row_num = 0;
130 - foreach ( $rows as $row ) {
131 - $result = array();
132 - $col_num = 0;
133 - foreach ( $row as $k => $v ) {
134 - $result[] = $v;
135 - if ( 0 === $row_num ) {
136 - $headers[] = array( 'type' => $this->get_col_type( $col_num++ ), 'label' => $k );
137 - }
83 + $row_num = 0;
84 + foreach ( $rows as $row ) {
85 + $result = array();
86 + $col_num = 0;
87 + foreach ( $row as $k => $v ) {
88 + $result[] = $v;
89 + if ( 0 === $row_num ) {
90 + $headers[] = array( 'type' => $this->get_col_type( $col_num++ ), 'label' => $k );
138 91 }
139 - $results[] = $result;
140 - $row_num++;
141 92 }
93 + $results[] = $result;
94 + $row_num++;
142 95 }
96 + }
143 97
144 - $this->_error = $wpdb->last_error;
98 + if ( $as_html ) {
99 + return $this->html( $headers, $results );
145 100 }
101 + return $this->object( $headers, $results );
146 102 }
147 - // Query log.
148 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Firing query %s to get results %s with error %s', $this->_query, print_r( $rows, true ), print_r( $wpdb->last_error, true ) ), 'debug', __FILE__, __LINE__ );
149 103
150 - if ( $as_html ) {
151 - $results = $this->html( $headers, $results );
152 - } else {
153 - $results = $this->object( $headers, $results );
154 - }
155 -
156 - return apply_filters( 'visualizer_db_query_results', $results, $headers, $as_html, $results_as_numeric_array, $raw_results, $this->_query, $this->_chart_id, $this->_params );
104 + $this->_error = $wpdb->last_error;
105 + return null;
157 106 }
158 107
159 108 /**
160 109 * Get the data type of the column.
@@ -216,9 +165,10 @@
216 165 foreach ( $results as $row ) {
217 166 $data[] = $this->_normalizeData( $row );
218 167 }
219 168 $this->_data = $data;
220 - return $this->_data;
169 +
170 + return true;
221 171 }
222 172
223 173 /**
224 174 * Returns the final query.