| @@ -59,8 +59,10 @@ | ||
| 59 | 59 | <div id='visualizer-db-query' style="display: none"> |
| 60 | 60 | <div class="visualizer-db-query-form"> |
| 61 | 61 | <div> |
| 62 | 62 | <form id='db-query-form'> |
| 63 | + <input type="hidden" name="chart_id" value="<?php echo $args[2]; ?>"> | |
| 64 | + <?php do_action( 'visualizer_db_query_add_layout', $args ); ?> | |
| 63 | 65 | <textarea name='query' class='visualizer-db-query' placeholder="<?php _e( 'Your query goes here', 'visualizer' ); ?>"><?php echo $query; ?></textarea> |
| 64 | 66 | </form> |
| 65 | 67 | <div class='db-wizard-error'></div> |
| 66 | 68 | </div> |
| @@ -71,8 +73,9 @@ | ||
| 71 | 73 | <div class='db-wizard-hints'> |
| 72 | 74 | <ul> |
| 73 | 75 | <li><?php echo sprintf( __( 'For examples of queries and links to resources that you can use with this feature, please click %1$shere%2$s', 'visualizer' ), '<a href="' . VISUALIZER_DB_QUERY_DOC_URL . '" target="_blank">', '</a>' ); ?></li> |
| 74 | 76 | <li><?php echo sprintf( __( 'Use %1$sControl+Space%2$s for autocompleting keywords or table names.', 'visualizer' ), '<span class="visualizer-emboss">', '</span>' ); ?></li> |
| 77 | + <?php do_action( 'visualizer_db_query_add_hints', $args ); ?> | |
| 75 | 78 | </ul> |
| 76 | 79 | </div> |
| 77 | 80 | <div class='db-wizard-results'></div> |
| 78 | 81 | |
| @@ -136,9 +139,13 @@ | ||
| 136 | 139 | |
| 137 | 140 | $url = get_post_meta( $id, Visualizer_Plugin::CF_JSON_URL, true ); |
| 138 | 141 | $root = get_post_meta( $id, Visualizer_Plugin::CF_JSON_ROOT, true ); |
| 139 | 142 | $paging = get_post_meta( $id, Visualizer_Plugin::CF_JSON_PAGING, true ); |
| 140 | - | |
| 143 | + $headers = get_post_meta( $id, Visualizer_Plugin::CF_JSON_HEADERS, true ); | |
| 144 | + if ( empty( $headers['method'] ) ) { | |
| 145 | + $headers['method'] = 'get'; | |
| 146 | + } | |
| 147 | + $methods = apply_filters( 'visualizer_json_request_methods', array( 'GET', 'POST' ) ); | |
| 141 | 148 | ?> |
| 142 | 149 | <div id="visualizer-json-screen" style="display: none"> |
| 143 | 150 | <div class="visualizer-json-form"> |
| 144 | 151 | <h3 class="viz-step step1"><?php _e( 'STEP 1: Specify the JSON endpoint/URL', 'visualizer' ); ?></h3> |
| @@ -145,9 +152,9 @@ | ||
| 145 | 152 | <div> |
| 146 | 153 | <form id="json-endpoint-form"> |
| 147 | 154 | <div class="json-wizard-hints"> |
| 148 | 155 | <ul class="info"> |
| 149 | - <li><?php echo sprintf( __( 'If you want to add authentication, add headers to the endpoint or change the request in any way, please refer to our document %1$shere%2$s.', 'visualizer' ), '<a href="https://docs.themeisle.com/article/1043-visualizer-how-to-extend-rest-endpoints-with-json-response" target="_blank">', '</a>' ); ?></li> | |
| 156 | + <li><?php echo sprintf( __( 'If you want to add authentication or headers to the endpoint or change the request in any way, please refer to our document %1$shere%2$s.', 'visualizer' ), '<a href="https://docs.themeisle.com/article/1043-visualizer-how-to-extend-rest-endpoints-with-json-response" target="_blank">', '</a>' ); ?></li> | |
| 150 | 157 | </ul> |
| 151 | 158 | </div> |
| 152 | 159 | |
| 153 | 160 | <input |
| @@ -155,10 +162,62 @@ | ||
| 155 | 162 | id="vz-import-json-url" |
| 156 | 163 | name="url" |
| 157 | 164 | value="<?php echo esc_url( $url ); ?>" |
| 158 | 165 | placeholder="<?php esc_html_e( 'Please enter the URL', 'visualizer' ); ?>" |
| 159 | - class="visualizer-input"> | |
| 166 | + class="visualizer-input json-form-element"> | |
| 160 | 167 | <button class="button button-secondary button-small" id="visualizer-json-fetch"><?php esc_html_e( 'Fetch Endpoint', 'visualizer' ); ?></button> |
| 168 | + | |
| 169 | + <div class="visualizer-json-subform"> | |
| 170 | + <h3 class="viz-substep"><?php _e( 'Headers', 'visualizer' ); ?></h3> | |
| 171 | + <div class="json-wizard-headers"> | |
| 172 | + <div class="json-wizard-header"> | |
| 173 | + <div><?php _e( 'Request Type', 'visualizer' ); ?></div> | |
| 174 | + <div> | |
| 175 | + <select name="method" class="json-form-element"> | |
| 176 | + <?php foreach ( $methods as $method ) { ?> | |
| 177 | + <option value="<?php echo $method; ?>" <?php selected( $headers['method'], $method ); ?>><?php echo $method; ?></option> | |
| 178 | + <?php } ?> | |
| 179 | + </select> | |
| 180 | + </div> | |
| 181 | + </div> | |
| 182 | + <div class="json-wizard-header"> | |
| 183 | + <div><?php _e( 'Credentials', 'visualizer' ); ?></div> | |
| 184 | + <div> | |
| 185 | + <input | |
| 186 | + type="text" | |
| 187 | + id="vz-import-json-username" | |
| 188 | + name="username" | |
| 189 | + value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'username', $headers['auth'] ) ? $headers['auth']['username'] : '' ); ?>" | |
| 190 | + placeholder="<?php esc_html_e( 'Username/Access Key', 'visualizer' ); ?>" | |
| 191 | + class="json-form-element"> | |
| 192 | + & | |
| 193 | + <input | |
| 194 | + type="password" | |
| 195 | + id="vz-import-json-password" | |
| 196 | + name="password" | |
| 197 | + value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'password', $headers['auth'] ) ? $headers['auth']['password'] : '' ); ?>" | |
| 198 | + placeholder="<?php esc_html_e( 'Password/Secret Key', 'visualizer' ); ?>" | |
| 199 | + class="json-form-element"> | |
| 200 | + </div> | |
| 201 | + </div> | |
| 202 | + <div class="json-wizard-header"> | |
| 203 | + <div></div> | |
| 204 | + <div><?php esc_html_e( 'OR', 'visualizer' ); ?></div> | |
| 205 | + </div> | |
| 206 | + <div class="json-wizard-header"> | |
| 207 | + <div><?php esc_html_e( 'Authorization', 'visualizer' ); ?></div> | |
| 208 | + <div> | |
| 209 | + <input | |
| 210 | + type="text" | |
| 211 | + id="vz-import-json-auth" | |
| 212 | + name="auth" | |
| 213 | + value="<?php echo ( ! empty( $headers ) && array_key_exists( 'auth', $headers ) ? $headers['auth']['auth'] : '' ); ?>" | |
| 214 | + placeholder="<?php esc_html_e( 'e.g. SharedKey <AccountName>:<Signature>', 'visualizer' ); ?>" | |
| 215 | + class="visualizer-input json-form-element"> | |
| 216 | + </div> | |
| 217 | + </div> | |
| 218 | + </div> | |
| 219 | + </div> | |
| 161 | 220 | </form> |
| 162 | 221 | </div> |
| 163 | 222 | <h3 class="viz-step step2 <?php echo empty( $url ) ? 'ui-state-disabled' : ''; ?> json-root-form"><?php _e( 'STEP 2: Choose the JSON root', 'visualizer' ); ?></h3> |
| 164 | 223 | <div> |
| @@ -163,9 +222,9 @@ | ||
| 163 | 222 | <h3 class="viz-step step2 <?php echo empty( $url ) ? 'ui-state-disabled' : ''; ?> json-root-form"><?php _e( 'STEP 2: Choose the JSON root', 'visualizer' ); ?></h3> |
| 164 | 223 | <div> |
| 165 | 224 | <form id="json-root-form"> |
| 166 | 225 | <input type="hidden" name="chart" value="<?php echo $id; ?>"> |
| 167 | - <select name="root" id="vz-import-json-root"> | |
| 226 | + <select name="root" id="vz-import-json-root" class="json-form-element"> | |
| 168 | 227 | <?php |
| 169 | 228 | if ( ! empty( $root ) ) { |
| 170 | 229 | ?> |
| 171 | 230 | <option value="<?php echo esc_attr( $root ); ?>"><?php echo str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $root ); ?></option> |
| @@ -172,9 +231,8 @@ | ||
| 172 | 231 | <?php |
| 173 | 232 | } |
| 174 | 233 | ?> |
| 175 | 234 | </select> |
| 176 | - <input type="hidden" name="url" value="<?php echo $url; ?>"> | |
| 177 | 235 | <button class="button button-secondary button-small" id="visualizer-json-parse"><?php esc_html_e( 'Parse Endpoint', 'visualizer' ); ?></button> |
| 178 | 236 | </form> |
| 179 | 237 | </div> |
| 180 | 238 | <h3 class="viz-step step3 <?php echo empty( $root ) ? 'ui-state-disabled' : ''; ?>"><?php _e( 'STEP 3: Specify miscellaneous parameters', 'visualizer' ); ?></h3> |
| @@ -181,14 +239,14 @@ | ||
| 181 | 239 | <div> |
| 182 | 240 | <form id="json-conclude-form-helper"> |
| 183 | 241 | <div class="<?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>"> |
| 184 | 242 | <div class="json-pagination"> |
| 185 | - <select name="paging" id="vz-import-json-paging" class="json-form-element" data-template='<?php echo sprintf( 'Get first %d pages using %s', apply_filters( 'visualizer_json_fetch_pages', 5, $url ), '?' ); ?>'> | |
| 186 | - <option value="0" class="static"><?php _e( 'Don\'t use pagination', 'visualizer' ); ?></option> | |
| 243 | + <select name="paging" id="vz-import-json-paging" class="json-form-element" data-template='<?php echo sprintf( 'Get results from the first %d pages using %s', apply_filters( 'visualizer_json_fetch_pages', 5, $url ), '?' ); ?>'> | |
| 244 | + <option value="0" class="static"><?php _e( 'Get results from the first page only', 'visualizer' ); ?></option> | |
| 187 | 245 | <?php |
| 188 | 246 | if ( ! empty( $paging ) ) { |
| 189 | 247 | ?> |
| 190 | - <option value="<?php echo esc_attr( $paging ); ?>"><?php echo sprintf( 'Get first %d pages using %s', apply_filters( 'visualizer_json_fetch_pages', 5, $url ), str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $paging ) ); ?></option> | |
| 248 | + <option value="<?php echo esc_attr( $paging ); ?>"><?php echo sprintf( 'Get results from the first %d pages using %s', apply_filters( 'visualizer_json_fetch_pages', 5, $url ), str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $paging ) ); ?></option> | |
| 191 | 249 | <?php |
| 192 | 250 | } |
| 193 | 251 | ?> |
| 194 | 252 | </select> |
| @@ -209,22 +267,20 @@ | ||
| 209 | 267 | </div> |
| 210 | 268 | <h3 class="viz-step step4 ui-state-disabled"><?php _e( 'STEP 4: Select the data to display in the chart', 'visualizer' ); ?></h3> |
| 211 | 269 | <div> |
| 212 | 270 | <form id="json-conclude-form" action="<?php echo $action; ?>" method="post" target="thehole"> |
| 213 | - <input type="hidden" name="url"> | |
| 214 | - <input type="hidden" name="root"> | |
| 215 | - <input type="hidden" name="chart" value="<?php echo $id; ?>"> | |
| 216 | - | |
| 217 | 271 | <div class="json-wizard-hints html-table-editor-hints"> |
| 218 | 272 | <ul class="info"> |
| 273 | + <li><?php _e( 'If you see Invalid Data in the table, you may have selected the wrong root to fetch data from. Please select an alternative from the JSON root dropdown.', 'visualizer' ); ?></li> | |
| 219 | 274 | <li><?php _e( 'Select whether to include the data in the chart. Each column selected will form one series.', 'visualizer' ); ?></li> |
| 220 | 275 | <li><?php _e( 'If a column is selected to be included, specify its data type.', 'visualizer' ); ?></li> |
| 221 | 276 | <li><?php _e( 'You can use drag/drop to reorder the columns but this column position is not saved. So when you reload the table, you may have to reorder again.', 'visualizer' ); ?></li> |
| 222 | 277 | <li><?php _e( 'You can select any number of columns but the chart type selected will determine how many will display in the chart.', 'visualizer' ); ?></li> |
| 278 | + <li><?php _e( 'Once you have made your selection, click \'Show Chart\' on the right to view the chart.', 'visualizer' ); ?></li> | |
| 223 | 279 | </ul> |
| 224 | 280 | </div> |
| 225 | 281 | <div class="json-table"></div> |
| 226 | - <button class="button button-primary" id="visualizer-json-conclude"><?php esc_html_e( 'Save & Show Chart', 'visualizer' ); ?></button> | |
| 282 | + <button class="button button-primary" style="display: none" id="visualizer-json-conclude"></button> | |
| 227 | 283 | </form> |
| 228 | 284 | </div> |
| 229 | 285 | </div> |
| 230 | 286 | </div> |
| @@ -261,9 +317,9 @@ | ||
| 261 | 317 | <div class="viz-html-table"> |
| 262 | 318 | <?php Visualizer_Render_Layout::show( 'editor-table', null, $chart_id, 'viz-html-table', true, true ); ?> |
| 263 | 319 | </div> |
| 264 | 320 | <input type="hidden" name="table_data" value="yes"> |
| 265 | - <button class="button button-primary" id="visualizer-save-html-table"><?php esc_html_e( 'Save & Show Chart', 'visualizer' ); ?></button> | |
| 321 | + <input type="hidden" name="editor-type" value="table"> | |
| 266 | 322 | </form> |
| 267 | 323 | </div> |
| 268 | 324 | |
| 269 | 325 | <?php Visualizer_Render_Layout::show( 'text-editor', $chart_id ); ?> |
| @@ -279,9 +335,9 @@ | ||
| 279 | 335 | * @access public |
| 280 | 336 | */ |
| 281 | 337 | public static function _renderTextEditor( $args ) { |
| 282 | 338 | $chart_id = $args[1]; |
| 283 | - $csv = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, array(), $chart_id, 'csv' ); | |
| 339 | + $csv = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, array(), $chart_id, 'csv-display' ); | |
| 284 | 340 | $data = ''; |
| 285 | 341 | if ( ! empty( $csv ) && isset( $csv['string'] ) ) { |
| 286 | 342 | $data = str_replace( PHP_EOL, "\n", $csv['string'] ); |
| 287 | 343 | } |
| @@ -287,9 +343,8 @@ | ||
| 287 | 343 | } |
| 288 | 344 | ?> |
| 289 | 345 | <div class="viz-simple-editor-type viz-text-editor"> |
| 290 | 346 | <textarea id="edited_text"><?php echo $data; ?></textarea> |
| 291 | - <button id="viz-text-editor-button" class="button button-primary"><?php _e( 'Save & Show Chart', 'visualizer' ); ?></button> | |
| 292 | 347 | </div> |
| 293 | 348 | <?php |
| 294 | 349 | } |
| 295 | 350 | |
| @@ -312,9 +367,9 @@ | ||
| 312 | 367 | $headers[] = $column['label']; |
| 313 | 368 | } |
| 314 | 369 | $chart = get_post( $chart_id ); |
| 315 | 370 | $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ); |
| 316 | - $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $type ); | |
| 371 | + $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( str_replace( "'", "\'", html_entity_decode( $chart->post_content ) ) ), $type ); | |
| 317 | 372 | } else { |
| 318 | 373 | $headers = array_keys( $data[0] ); |
| 319 | 374 | } |
| 320 | 375 | |
| @@ -356,9 +411,9 @@ | ||
| 356 | 411 | if ( $editable_data ) { |
| 357 | 412 | echo '<select name="type[]">'; |
| 358 | 413 | } else { |
| 359 | 414 | echo '<input name="header[]" type="hidden" value="' . $header . '">'; |
| 360 | - echo '<select name="type[' . $header . ']">'; | |
| 415 | + echo '<select name="type[' . $header . ']" class="viz-select-data-type">'; | |
| 361 | 416 | } |
| 362 | 417 | echo '<option value="" title="' . __( 'Exclude from chart', 'visualizer' ) . '">' . __( 'Exclude', 'visualizer' ) . '</option>'; |
| 363 | 418 | echo '<option value="0" disabled title="' . __( 'Include in chart and select data type', 'visualizer' ) . '">--' . __( 'OR', 'visualizer' ) . '--</option>'; |
| 364 | 419 | |
| @@ -375,17 +430,22 @@ | ||
| 375 | 430 | // for remote sources, the data exists inside 'data'. |
| 376 | 431 | if ( array_key_exists( 'data', $data ) ) { |
| 377 | 432 | $data = $data['data']; |
| 378 | 433 | } |
| 434 | + | |
| 379 | 435 | foreach ( $data as $row ) { |
| 380 | 436 | echo '<tr>'; |
| 381 | 437 | echo '<th>' . __( 'Value', 'visualizer' ) . '</th>'; |
| 382 | 438 | $index = 0; |
| 439 | + if ( empty( $row ) ) { | |
| 440 | + echo '<td></td>'; | |
| 441 | + continue; | |
| 442 | + } | |
| 383 | 443 | foreach ( array_values( $row ) as $value ) { |
| 384 | 444 | if ( $editable_data ) { |
| 385 | - echo '<td><input type="text" name="data' . $index++ . '[]" value="' . esc_attr( $value ) . '"></td>'; | |
| 445 | + echo '<td><input type="text" name="data' . $index++ . '[]" value="' . esc_attr( stripslashes( $value ) ) . '"></td>'; | |
| 386 | 446 | } else { |
| 387 | - echo '<td>' . $value . '</td>'; | |
| 447 | + echo '<td>' . ( is_array( $value ) ? __( 'Invalid Data', 'visualizer' ) : $value ) . '</td>'; | |
| 388 | 448 | } |
| 389 | 449 | } |
| 390 | 450 | |
| 391 | 451 | echo '</tr>'; |