Skip to content

Commit 613c8ad

Browse files
committed
chore(dev): remove legacy block editor code
1 parent 94f9316 commit 613c8ad

49 files changed

Lines changed: 38 additions & 7371 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

classes/Visualizer/Gutenberg/Block.php

Lines changed: 2 additions & 314 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,10 @@ private function __construct() {
6767
* Enqueue front end and editor JavaScript and CSS
6868
*/
6969
public function enqueue_gutenberg_scripts() {
70-
global $wp_version, $pagenow;
70+
global $pagenow;
7171

7272
$blockPath = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/block.js';
73-
$handsontableJS = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/handsontable.js';
7473
$stylePath = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/block.css';
75-
$handsontableCSS = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/handsontable.css';
7674

7775
if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) {
7876
$version = filemtime( VISUALIZER_ABSPATH . '/classes/Visualizer/Gutenberg/build/block.js' );
@@ -89,59 +87,22 @@ public function enqueue_gutenberg_scripts() {
8987
}
9088

9189
// Enqueue the bundled block JS file
92-
wp_enqueue_script( 'handsontable', $handsontableJS );
93-
wp_enqueue_script( 'visualizer-gutenberg-block', $blockPath, array( 'wp-api', 'handsontable', 'visualizer-datatables', 'moment', 'lodash' ), $version, true );
94-
95-
$type = 'community';
96-
97-
if ( Visualizer_Module::is_pro() ) {
98-
$type = 'pro';
99-
if ( apply_filters( 'visualizer_is_business', false ) ) {
100-
$type = 'business';
101-
}
102-
}
103-
104-
$table_col_mapping = Visualizer_Source_Query_Params::get_all_db_tables_column_mapping( null, false );
90+
wp_enqueue_script( 'visualizer-gutenberg-block', $blockPath, array( 'wp-api', 'visualizer-datatables', 'moment', 'lodash' ), $version, true );
10591

10692
$translation_array = array(
107-
'isPro' => $type,
108-
'proTeaser' => tsdk_utmify( Visualizer_Plugin::PRO_TEASER_URL, 'blockupsell'),
109-
'absurl' => VISUALIZER_ABSURL,
110-
'charts' => Visualizer_Module_Admin::_getChartTypesLocalized(),
11193
'adminPage' => menu_page_url( 'visualizer', false ),
11294
'createChart' => add_query_arg( array( 'action' => 'visualizer-create-chart', 'library' => 'yes', 'type' => '', 'chart-library' => '', 'tab' => 'visualizer' ), admin_url( 'admin-ajax.php' ) ),
113-
'sqlTable' => $table_col_mapping,
11495
'chartsPerPage' => defined( 'TI_E2E_TESTING' ) ? 20 : 6,
115-
'proFeaturesLocked' => Visualizer_Module_Admin::proFeaturesLocked(),
11696
'isFullSiteEditor' => 'site-editor.php' === $pagenow,
117-
'legacyBlockEdit' => apply_filters( 'visualizer_legacy_block_edit', false ),
11897
/* translators: %1$s: opening tag, %2$s: closing tag */
11998
'blockEditDoc' => sprintf( __( 'The editor for managing chart settings has been removed from the block editor. You can find more information in this %1$sdocumentation%2$s', 'visualizer' ), '<a href="https://docs.themeisle.com/article/1705-how-can-i-display-a-chart#using-visualizer-block" target="_blank">', '</a>' ),
12099
'chartEditUrl' => admin_url( 'admin-ajax.php' ),
121100
);
122101
wp_localize_script( 'visualizer-gutenberg-block', 'visualizerLocalize', $translation_array );
123102

124103
// Enqueue frontend and editor block styles
125-
wp_enqueue_style( 'handsontable', $handsontableCSS );
126104
wp_enqueue_style( 'visualizer-gutenberg-block', $stylePath, array( 'visualizer-datatables' ), $version );
127105

128-
if ( version_compare( $wp_version, '4.9.0', '>' ) ) {
129-
130-
wp_enqueue_code_editor(
131-
array(
132-
'type' => 'sql',
133-
'codemirror' => array(
134-
'autofocus' => true,
135-
'lineWrapping' => true,
136-
'dragDrop' => false,
137-
'matchBrackets' => true,
138-
'autoCloseBrackets' => true,
139-
'extraKeys' => array( 'Shift-Space' => 'autocomplete' ),
140-
'hintOptions' => array( 'tables' => $table_col_mapping ),
141-
),
142-
)
143-
);
144-
}
145106
}
146107
/**
147108
* Hook server side rendering into render callback
@@ -216,72 +177,6 @@ public function register_rest_endpoints() {
216177
)
217178
);
218179

219-
register_rest_route(
220-
'visualizer/v' . VISUALIZER_REST_VERSION,
221-
'/get-query-data',
222-
array(
223-
'methods' => 'GET',
224-
'callback' => array( $this, 'get_query_data' ),
225-
'permission_callback' => function () {
226-
return current_user_can( 'edit_posts' );
227-
},
228-
)
229-
);
230-
231-
register_rest_route(
232-
'visualizer/v' . VISUALIZER_REST_VERSION,
233-
'/get-json-root',
234-
array(
235-
'methods' => 'GET',
236-
'callback' => array( $this, 'get_json_root_data' ),
237-
'args' => array(
238-
'url' => array(
239-
'sanitize_callback' => 'esc_url_raw',
240-
),
241-
),
242-
'permission_callback' => function () {
243-
return current_user_can( 'edit_posts' );
244-
},
245-
)
246-
);
247-
248-
register_rest_route(
249-
'visualizer/v' . VISUALIZER_REST_VERSION,
250-
'/get-json-data',
251-
array(
252-
'methods' => 'GET',
253-
'callback' => array( $this, 'get_json_data' ),
254-
'args' => array(
255-
'url' => array(
256-
'sanitize_callback' => 'esc_url_raw',
257-
),
258-
'chart' => array(
259-
'sanitize_callback' => 'absint',
260-
),
261-
),
262-
'permission_callback' => function () {
263-
return current_user_can( 'edit_posts' );
264-
},
265-
)
266-
);
267-
268-
register_rest_route(
269-
'visualizer/v' . VISUALIZER_REST_VERSION,
270-
'/set-json-data',
271-
array(
272-
'methods' => 'GET',
273-
'callback' => array( $this, 'set_json_data' ),
274-
'args' => array(
275-
'url' => array(
276-
'sanitize_callback' => 'esc_url_raw',
277-
),
278-
),
279-
'permission_callback' => function () {
280-
return current_user_can( 'edit_posts' );
281-
},
282-
)
283-
);
284-
285180
register_rest_route(
286181
'visualizer/v' . VISUALIZER_REST_VERSION,
287182
'/update-chart',
@@ -299,39 +194,6 @@ public function register_rest_endpoints() {
299194
)
300195
);
301196

302-
register_rest_route(
303-
'visualizer/v' . VISUALIZER_REST_VERSION,
304-
'/upload-data',
305-
array(
306-
'methods' => 'POST',
307-
'callback' => array( $this, 'upload_csv_data' ),
308-
'args' => array(
309-
'url' => array(
310-
'sanitize_callback' => 'esc_url_raw',
311-
),
312-
),
313-
'permission_callback' => function () {
314-
return current_user_can( 'edit_posts' );
315-
},
316-
)
317-
);
318-
319-
register_rest_route(
320-
'visualizer/v' . VISUALIZER_REST_VERSION,
321-
'/get-permission-data',
322-
array(
323-
'methods' => 'GET',
324-
'callback' => array( $this, 'get_permission_data' ),
325-
'args' => array(
326-
'type' => array(
327-
'sanitize_callback' => 'sanitize_text_field',
328-
),
329-
),
330-
'permission_callback' => function () {
331-
return current_user_can( 'edit_posts' );
332-
},
333-
)
334-
);
335197
}
336198

337199
/**
@@ -486,102 +348,6 @@ public function get_visualizer_data( $post ) {
486348
return $data;
487349
}
488350

489-
/**
490-
* Returns the data for the query.
491-
*
492-
* @access public
493-
*/
494-
public function get_query_data( $data ) {
495-
if ( ! current_user_can( 'administrator' ) || ( is_multisite() && ! is_super_admin() ) ) {
496-
return false;
497-
}
498-
499-
$source = new Visualizer_Source_Query( stripslashes( $data['query'] ) );
500-
$html = $source->fetch( true );
501-
$source->fetch( false );
502-
$name = $source->getSourceName();
503-
$series = $source->getSeries();
504-
$data = $source->getRawData();
505-
$error = '';
506-
if ( empty( $html ) ) {
507-
$error = $source->get_error();
508-
wp_send_json_error( array( 'msg' => $error ) );
509-
}
510-
wp_send_json_success( array( 'table' => $html, 'name' => $name, 'series' => $series, 'data' => $data ) );
511-
}
512-
513-
/**
514-
* Returns the JSON root.
515-
*
516-
* @access public
517-
*/
518-
public function get_json_root_data( $data ) {
519-
if ( ! current_user_can( 'edit_posts' ) ) {
520-
return false;
521-
}
522-
523-
$source = new Visualizer_Source_Json( $data );
524-
525-
$roots = $source->fetchRoots();
526-
if ( empty( $roots ) ) {
527-
wp_send_json_error( array( 'msg' => $source->get_error() ) );
528-
}
529-
530-
wp_send_json_success( array( 'url' => $data['url'], 'roots' => $roots ) );
531-
}
532-
533-
/**
534-
* Returns the JSON data.
535-
*
536-
* @access public
537-
*/
538-
public function get_json_data( $data ) {
539-
if ( ! current_user_can( 'edit_posts' ) ) {
540-
return false;
541-
}
542-
543-
$chart_id = $data['chart'];
544-
545-
if ( empty( $chart_id ) ) {
546-
wp_die();
547-
}
548-
549-
$source = new Visualizer_Source_Json( $data );
550-
$source->fetch();
551-
$table = $source->getRawData();
552-
553-
if ( empty( $table ) ) {
554-
wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) );
555-
}
556-
557-
$table = Visualizer_Render_Layout::show( 'editor-table', $table, $chart_id, 'viz-json-table', false, false );
558-
wp_send_json_success( array( 'table' => $table, 'root' => $data['root'], 'url' => $data['url'], 'paging' => $source->getPaginationElements() ) );
559-
}
560-
561-
/**
562-
* Set the JSON data.
563-
*
564-
* @access public
565-
*/
566-
public function set_json_data( $data ) {
567-
if ( ! current_user_can( 'edit_posts' ) ) {
568-
return false;
569-
}
570-
571-
$source = new Visualizer_Source_Json( $data );
572-
573-
$table = $source->fetch();
574-
if ( empty( $table ) ) {
575-
wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) );
576-
}
577-
578-
$source->fetchFromEditableTable();
579-
$name = $source->getSourceName();
580-
$series = json_encode( $source->getSeries() );
581-
$data = json_encode( $source->getRawData() );
582-
wp_send_json_success( array( 'name' => $name, 'series' => $series, 'data' => $data ) );
583-
}
584-
585351
/**
586352
* Rest Callback Method
587353
*/
@@ -768,84 +534,6 @@ public function toUTF8( $datum ) {
768534
return $datum;
769535
}
770536

771-
/**
772-
* Handle remote CSV data
773-
*/
774-
public function upload_csv_data( $data ) {
775-
if ( ! current_user_can( 'edit_posts' ) ) {
776-
return false;
777-
}
778-
779-
$remote_data = false;
780-
if ( isset( $data['url'] ) && function_exists( 'wp_http_validate_url' ) ) {
781-
$remote_data = wp_http_validate_url( $data['url'] );
782-
}
783-
if ( false !== $remote_data && ! is_wp_error( $remote_data ) ) {
784-
$source = new Visualizer_Source_Csv_Remote( $remote_data );
785-
if ( $source->fetch() ) {
786-
$temp = $source->getData();
787-
if ( is_string( $temp ) && is_array( unserialize( $temp ) ) ) {
788-
$content['series'] = $source->getSeries();
789-
$content['data'] = $source->getRawData();
790-
return $content;
791-
} else {
792-
return new \WP_REST_Response( array( 'failed' => sprintf( 'Invalid CSV URL' ) ) );
793-
}
794-
} else {
795-
return new \WP_REST_Response( array( 'failed' => sprintf( 'Invalid CSV URL' ) ) );
796-
}
797-
} else {
798-
return new \WP_REST_Response( array( 'failed' => sprintf( 'Invalid CSV URL' ) ) );
799-
}
800-
}
801-
802-
/**
803-
* Get permission data
804-
*/
805-
public function get_permission_data( $data ) {
806-
if ( ! current_user_can( 'edit_posts' ) ) {
807-
return false;
808-
}
809-
810-
$options = array();
811-
switch ( $data['type'] ) {
812-
case 'users':
813-
$query = new WP_User_Query(
814-
array(
815-
'number' => 1000,
816-
'orderby' => 'display_name',
817-
'fields' => array( 'ID', 'display_name' ),
818-
'count_total' => false,
819-
)
820-
);
821-
$users = $query->get_results();
822-
if ( ! empty( $users ) ) {
823-
$i = 0;
824-
foreach ( $users as $user ) {
825-
$options[ $i ]['value'] = $user->ID;
826-
$options[ $i ]['label'] = $user->display_name;
827-
++$i;
828-
}
829-
}
830-
break;
831-
case 'roles':
832-
if ( ! function_exists( 'get_editable_roles' ) ) {
833-
require_once ABSPATH . 'wp-admin/includes/user.php';
834-
}
835-
$roles = get_editable_roles();
836-
if ( ! empty( $roles ) ) {
837-
$i = 0;
838-
foreach ( get_editable_roles() as $name => $info ) {
839-
$options[ $i ]['value'] = $name;
840-
$options[ $i ]['label'] = $name;
841-
++$i;
842-
}
843-
}
844-
break;
845-
}
846-
return $options;
847-
}
848-
849537
/**
850538
* Filter Rest Query
851539
*/

0 commit comments

Comments
 (0)