@@ -9,7 +9,6 @@ |
||
| 9 | 9 | |
| 10 | 10 | use Exception; |
| 11 | 11 | use WordPress\Tabulate\DB\Exception as TabulateException; |
| 12 | -use WordPress\Tabulate\DB\Table; |
|
| 13 | 12 | use WP_Admin_Bar; |
| 14 | 13 | use WP_Filesystem_Base; |
| 15 | 14 | use wpdb; |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | // Home page (also change the first submenu item's title). |
| 79 | 79 | add_menu_page( 'Tabulate', 'Tabulate', 'read', TABULATE_SLUG, $dispatch_callback ); |
| 80 | - $page_title = ( isset( $_GET['table'] ) ) ? Text::titlecase( $_GET['table'] ) : 'Tabulate'; |
|
| 80 | + $page_title = ( isset( $_GET[ 'table' ] ) ) ? Text::titlecase( $_GET[ 'table' ] ) : 'Tabulate'; |
|
| 81 | 81 | add_submenu_page( TABULATE_SLUG, $page_title, 'Overview', 'read', TABULATE_SLUG, $dispatch_callback ); |
| 82 | 82 | |
| 83 | 83 | // Add submenu pages. |
@@ -134,17 +134,17 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | // Only dispatch when it's our page. |
| 136 | 136 | $slug_lenth = strlen( TABULATE_SLUG ); |
| 137 | - if ( ! isset( $request['page'] ) || substr( $request['page'], 0, $slug_lenth ) !== TABULATE_SLUG ) { |
|
| 137 | + if ( ! isset( $request[ 'page' ] ) || substr( $request[ 'page' ], 0, $slug_lenth ) !== TABULATE_SLUG ) { |
|
| 138 | 138 | return; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // Discern the controller name, based on an explicit request parameter, or |
| 142 | 142 | // the trailing part of the page slug (i.e. after 'tabulate_'). |
| 143 | 143 | $controller_name = 'home'; |
| 144 | - if ( isset( $request['controller'] ) && strlen( $request['controller'] ) > 0 ) { |
|
| 145 | - $controller_name = $request['controller']; |
|
| 146 | - } elseif ( isset( $request['page'] ) && strlen( $request['page'] ) > $slug_lenth ) { |
|
| 147 | - $controller_name = substr( $request['page'], $slug_lenth + 1 ); |
|
| 144 | + if ( isset( $request[ 'controller' ] ) && strlen( $request[ 'controller' ] ) > 0 ) { |
|
| 145 | + $controller_name = $request[ 'controller' ]; |
|
| 146 | + } elseif ( isset( $request[ 'page' ] ) && strlen( $request[ 'page' ] ) > $slug_lenth ) { |
|
| 147 | + $controller_name = substr( $request[ 'page' ], $slug_lenth + 1 ); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // Create the controller and run the action. |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | } |
| 155 | 155 | $controller = new $controller_classname( $this->wpdb ); |
| 156 | 156 | $controller->set_filesystem( $this->filesystem ); |
| 157 | - $action = ! empty( $request['action'] ) ? $request['action'] : 'index'; |
|
| 158 | - unset( $request['page'], $request['controller'], $request['action'] ); |
|
| 157 | + $action = ! empty( $request[ 'action' ] ) ? $request[ 'action' ] : 'index'; |
|
| 158 | + unset( $request[ 'page' ], $request[ 'controller' ], $request[ 'action' ] ); |
|
| 159 | 159 | try { |
| 160 | 160 | $this->output = $controller->$action( $request ); |
| 161 | 161 | } catch ( Exception $e ) { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | $script_url = plugins_url( TABULATE_SLUG ) . '/assets/scripts.js'; |
| 203 | 203 | $deps = array( 'jquery-ui-autocomplete', 'tabulate-leaflet', 'tabulate-maskedinput', 'tabulate-timepicker' ); |
| 204 | 204 | if ( Util::is_plugin_active( 'rest-api/plugin.php' ) ) { |
| 205 | - $deps[] = 'wp-api'; |
|
| 205 | + $deps[ ] = 'wp-api'; |
|
| 206 | 206 | } |
| 207 | 207 | wp_enqueue_script( 'tabulate-scripts', $script_url, $deps, TABULATE_VERSION, true ); |
| 208 | 208 | |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | $db = new Database( $this->wpdb ); |
| 34 | 34 | $template->action = 'structure'; |
| 35 | 35 | $template->tables = $db->get_tables(); |
| 36 | - if ( isset( $args['table'] ) ) { |
|
| 37 | - $template->table = $db->get_table( $args['table'] ); |
|
| 36 | + if ( isset( $args[ 'table' ] ) ) { |
|
| 37 | + $template->table = $db->get_table( $args[ 'table' ] ); |
|
| 38 | 38 | $template->record = $template->table->get_default_record(); |
| 39 | 39 | } |
| 40 | 40 | $template->xtypes = Column::get_xtypes(); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | public function newtable( $args ) { |
| 50 | 50 | // Create table. |
| 51 | 51 | $db = new Database( $this->wpdb ); |
| 52 | - $table = $db->create_table( $args['new_table_name'] ); |
|
| 52 | + $table = $db->create_table( $args[ 'new_table_name' ] ); |
|
| 53 | 53 | |
| 54 | 54 | // Redirect user with message. |
| 55 | 55 | $template = new Template( 'table/schema.html' ); |
@@ -65,49 +65,49 @@ discard block |
||
| 65 | 65 | * @param string[] $args The request arguments. |
| 66 | 66 | */ |
| 67 | 67 | public function save( $args ) { |
| 68 | - if ( ! isset( $args['table'] ) || ! current_user_can( 'promote_users' ) ) { |
|
| 68 | + if ( ! isset( $args[ 'table' ] ) || ! current_user_can( 'promote_users' ) ) { |
|
| 69 | 69 | $url = admin_url( 'admin.php?page=tabulate' ); |
| 70 | 70 | wp_safe_redirect( $url ); |
| 71 | 71 | exit; |
| 72 | 72 | } |
| 73 | 73 | $db = new Database( $this->wpdb ); |
| 74 | - $table = $db->get_table( $args['table'] ); |
|
| 75 | - if ( isset( $args['delete'] ) ) { |
|
| 74 | + $table = $db->get_table( $args[ 'table' ] ); |
|
| 75 | + if ( isset( $args[ 'delete' ] ) ) { |
|
| 76 | 76 | wp_safe_redirect( $table->get_url( 'delete', null, 'schema' ) ); |
| 77 | 77 | exit; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Rename. |
| 81 | - $new_name = $args['table']; |
|
| 82 | - if ( $table instanceof Table && ! empty( $args['new_name'] ) ) { |
|
| 83 | - $table->rename( $args['new_name'] ); |
|
| 81 | + $new_name = $args[ 'table' ]; |
|
| 82 | + if ( $table instanceof Table && ! empty( $args[ 'new_name' ] ) ) { |
|
| 83 | + $table->rename( $args[ 'new_name' ] ); |
|
| 84 | 84 | $new_name = $table->get_name(); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // Set comment. |
| 88 | - if ( isset( $args['new_comment'] ) ) { |
|
| 89 | - $table->set_comment( $args['new_comment'] ); |
|
| 88 | + if ( isset( $args[ 'new_comment' ] ) ) { |
|
| 89 | + $table->set_comment( $args[ 'new_comment' ] ); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // Update columns. |
| 93 | 93 | $previous_column_name = ''; |
| 94 | - foreach ( $args['columns'] as $col_info ) { |
|
| 94 | + foreach ( $args[ 'columns' ] as $col_info ) { |
|
| 95 | 95 | // Validate inputs. |
| 96 | - $old_col_name = isset( $col_info['old_name'] ) ? $col_info['old_name'] : null; |
|
| 97 | - $new_col_name = isset( $col_info['new_name'] ) ? $col_info['new_name'] : null; |
|
| 98 | - $xtype = isset( $col_info['xtype'] ) ? $col_info['xtype'] : null; |
|
| 99 | - $size = isset( $col_info['size'] ) ? $col_info['size'] : null; |
|
| 100 | - $nullable = isset( $col_info['nullable'] ); |
|
| 101 | - $default = isset( $col_info['default'] ) ? $col_info['default'] : null; |
|
| 102 | - $auto_increment = isset( $args['auto_increment'] ) && $args['auto_increment'] === $old_col_name; |
|
| 103 | - $unique = isset( $col_info['unique'] ); |
|
| 104 | - $comment = isset( $col_info['comment'] ) ? $col_info['comment'] : null; |
|
| 105 | - $target_table = isset( $col_info['target_table'] ) ? $db->get_table( $col_info['target_table'] ) : null; |
|
| 96 | + $old_col_name = isset( $col_info[ 'old_name' ] ) ? $col_info[ 'old_name' ] : null; |
|
| 97 | + $new_col_name = isset( $col_info[ 'new_name' ] ) ? $col_info[ 'new_name' ] : null; |
|
| 98 | + $xtype = isset( $col_info[ 'xtype' ] ) ? $col_info[ 'xtype' ] : null; |
|
| 99 | + $size = isset( $col_info[ 'size' ] ) ? $col_info[ 'size' ] : null; |
|
| 100 | + $nullable = isset( $col_info[ 'nullable' ] ); |
|
| 101 | + $default = isset( $col_info[ 'default' ] ) ? $col_info[ 'default' ] : null; |
|
| 102 | + $auto_increment = isset( $args[ 'auto_increment' ] ) && $args[ 'auto_increment' ] === $old_col_name; |
|
| 103 | + $unique = isset( $col_info[ 'unique' ] ); |
|
| 104 | + $comment = isset( $col_info[ 'comment' ] ) ? $col_info[ 'comment' ] : null; |
|
| 105 | + $target_table = isset( $col_info[ 'target_table' ] ) ? $db->get_table( $col_info[ 'target_table' ] ) : null; |
|
| 106 | 106 | |
| 107 | 107 | // Change existing or insert new column. |
| 108 | 108 | $altered = false; |
| 109 | 109 | if ( $old_col_name ) { |
| 110 | - $col = $table->get_column( $col_info['old_name'] ); |
|
| 110 | + $col = $table->get_column( $col_info[ 'old_name' ] ); |
|
| 111 | 111 | if ( $col instanceof Column ) { |
| 112 | 112 | $col->alter( $new_col_name, $xtype, $size, $nullable, $default, $auto_increment, $unique, $comment, $target_table, $previous_column_name ); |
| 113 | 113 | $altered = true; |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | public function delete( $args ) { |
| 138 | 138 | $template = new Template( 'table/delete.html' ); |
| 139 | 139 | $db = new Database( $this->wpdb ); |
| 140 | - $table = $db->get_table( $args['table'] ); |
|
| 140 | + $table = $db->get_table( $args[ 'table' ] ); |
|
| 141 | 141 | |
| 142 | 142 | // Ask for confirmation. |
| 143 | - if ( ! isset( $args['confirm_deletion'] ) ) { |
|
| 143 | + if ( ! isset( $args[ 'confirm_deletion' ] ) ) { |
|
| 144 | 144 | $template->table = $table; |
| 145 | 145 | return $template->render(); |
| 146 | 146 | } |