| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | namespace WPCoder\Dashboard; |
| 4 | 4 | |
| 5 | 5 | defined( 'ABSPATH' ) || exit; |
| 6 | 6 | |
| 7 | -use WPCoder\WOW_Plugin; | |
| 7 | +use WPCoder\WPCoder; | |
| 8 | 8 | |
| 9 | 9 | class DBManager { |
| 10 | 10 | |
| 11 | 11 | public static function remove_item() { |
| @@ -12,14 +12,14 @@ | ||
| 12 | 12 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
| 13 | 13 | $action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
| 14 | 14 | $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : ''; |
| 15 | 15 | |
| 16 | - if ( ( $page !== WOW_Plugin::SLUG ) || ( $action !== 'delete' ) || empty( $id ) ) { | |
| 16 | + if ( ( $page !== WPCoder::SLUG ) || ( $action !== 'delete' ) || empty( $id ) ) { | |
| 17 | 17 | return false; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | global $wpdb; |
| 21 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 21 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 22 | 22 | |
| 23 | 23 | $result = $wpdb->delete( $table, [ 'id' => $id ], [ '%d' ] ); |
| 24 | 24 | |
| 25 | 25 | if ( $result ) { |
| @@ -36,21 +36,31 @@ | ||
| 36 | 36 | return false; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | global $wpdb; |
| 40 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 40 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 41 | 41 | |
| 42 | 42 | return $wpdb->delete( $table, [ 'id' => $id ], [ '%d' ] ); |
| 43 | - | |
| 44 | 43 | } |
| 45 | 44 | |
| 46 | - public static function create( $columns ): void { | |
| 47 | - | |
| 45 | + public static function create(): void { | |
| 48 | 46 | global $wpdb; |
| 49 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 47 | + $table_name = $wpdb->prefix . WPCoder::PREFIX; | |
| 48 | + $charset_collate = $wpdb->get_charset_collate(); | |
| 50 | 49 | |
| 51 | - $sql = "CREATE TABLE IF NOT EXISTS $table ($columns) DEFAULT CHARACTER SET {$wpdb->charset} COLLATE {$wpdb->collate};"; | |
| 52 | - | |
| 50 | + $sql = "CREATE TABLE $table_name ( | |
| 51 | + id mediumint(9) NOT NULL AUTO_INCREMENT, | |
| 52 | + title VARCHAR(200) NOT NULL, | |
| 53 | + html_code LONGTEXT, | |
| 54 | + css_code LONGTEXT, | |
| 55 | + js_code LONGTEXT, | |
| 56 | + php_code LONGTEXT, | |
| 57 | + param LONGTEXT, | |
| 58 | + status BOOLEAN, | |
| 59 | + mode BOOLEAN, | |
| 60 | + tag TEXT, | |
| 61 | + PRIMARY KEY (id) | |
| 62 | + ) $charset_collate;"; | |
| 53 | 63 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 54 | 64 | dbDelta( $sql ); |
| 55 | 65 | } |
| 56 | 66 | |
| @@ -55,9 +65,9 @@ | ||
| 55 | 65 | } |
| 56 | 66 | |
| 57 | 67 | public static function get_all_data() { |
| 58 | 68 | global $wpdb; |
| 59 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 69 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 60 | 70 | $result = $wpdb->get_results( "SELECT * FROM $table ORDER BY id ASC" ); |
| 61 | 71 | |
| 62 | 72 | return ! empty( $result ) ? $result : false; |
| 63 | 73 | } |
| @@ -66,9 +76,9 @@ | ||
| 66 | 76 | if ( empty( $id ) ) { |
| 67 | 77 | return false; |
| 68 | 78 | } |
| 69 | 79 | global $wpdb; |
| 70 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 80 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 71 | 81 | $query = $wpdb->prepare( "SELECT * FROM $table WHERE id=%d", absint( $id ) ); |
| 72 | 82 | |
| 73 | 83 | return $wpdb->get_row( $query ); |
| 74 | 84 | } |
| @@ -78,9 +88,9 @@ | ||
| 78 | 88 | return false; |
| 79 | 89 | } |
| 80 | 90 | |
| 81 | 91 | global $wpdb; |
| 82 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 92 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 83 | 93 | $query = $wpdb->prepare( "SELECT * FROM $table WHERE title=%s", sanitize_text_field( $title ) ); |
| 84 | 94 | |
| 85 | 95 | return $wpdb->get_row( $query ); |
| 86 | 96 | } |
| @@ -85,22 +95,29 @@ | ||
| 85 | 95 | return $wpdb->get_row( $query ); |
| 86 | 96 | } |
| 87 | 97 | |
| 88 | 98 | public static function update( $data, $where, $data_formats ): void { |
| 99 | + if ( ! current_user_can( 'unfiltered_html' ) ) { | |
| 100 | + return; | |
| 101 | + } | |
| 102 | + | |
| 89 | 103 | global $wpdb; |
| 90 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 104 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 91 | 105 | $result = $wpdb->update( $table, $data, $where, $data_formats ); |
| 92 | 106 | } |
| 93 | 107 | |
| 94 | 108 | public static function insert( $data, $data_formats ) { |
| 109 | + if ( ! current_user_can( 'unfiltered_html' ) ) { | |
| 110 | + return false; | |
| 111 | + } | |
| 112 | + | |
| 95 | 113 | global $wpdb; |
| 96 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 114 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 97 | 115 | |
| 98 | 116 | $result = $wpdb->insert( $table, $data, $data_formats ); |
| 99 | 117 | |
| 100 | 118 | if ( $result ) { |
| 101 | 119 | return $wpdb->insert_id; |
| 102 | - | |
| 103 | 120 | } |
| 104 | 121 | |
| 105 | 122 | return false; |
| 106 | 123 | } |
| @@ -106,9 +123,9 @@ | ||
| 106 | 123 | } |
| 107 | 124 | |
| 108 | 125 | public static function check_row( $id = '' ): bool { |
| 109 | 126 | global $wpdb; |
| 110 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 127 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 111 | 128 | if ( empty( $id ) ) { |
| 112 | 129 | return false; |
| 113 | 130 | } |
| 114 | 131 | |
| @@ -121,9 +138,9 @@ | ||
| 121 | 138 | } |
| 122 | 139 | |
| 123 | 140 | public static function get_columns() { |
| 124 | 141 | global $wpdb; |
| 125 | - $table_name = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 142 | + $table_name = $wpdb->prefix . WPCoder::PREFIX; | |
| 126 | 143 | |
| 127 | 144 | return $wpdb->get_results( "DESCRIBE $table_name" ); |
| 128 | 145 | } |
| 129 | 146 | |
| @@ -128,9 +145,9 @@ | ||
| 128 | 145 | } |
| 129 | 146 | |
| 130 | 147 | public static function display_tags(): void { |
| 131 | 148 | global $wpdb; |
| 132 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 149 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 133 | 150 | $result = $wpdb->get_results( "SELECT * FROM $table order by tag desc", ARRAY_A ); |
| 134 | 151 | $tags = []; |
| 135 | 152 | if ( ! empty( $result ) ) { |
| 136 | 153 | foreach ( $result as $column ) { |
| @@ -147,9 +164,9 @@ | ||
| 147 | 164 | } |
| 148 | 165 | |
| 149 | 166 | public static function get_tags_from_table() { |
| 150 | 167 | global $wpdb; |
| 151 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 168 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 152 | 169 | $all_tags = $wpdb->get_results( "SELECT DISTINCT tag FROM $table ORDER BY tag ASC", ARRAY_A ); |
| 153 | 170 | |
| 154 | 171 | return ! empty( $all_tags ) ? $all_tags : false; |
| 155 | 172 | } |