PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.11
Code Manager v1.0.11
1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / Code_Manager / Code_Manager_Import_File.php
code-manager / Code_Manager Last commit date
Code_Manager.php 4 years ago Code_Manager_Dashboard.php 4 years ago Code_Manager_Export.php 4 years ago Code_Manager_Form.php 4 years ago Code_Manager_Import.php 4 years ago Code_Manager_Import_File.php 4 years ago Code_Manager_List.php 4 years ago Code_Manager_List_View.php 4 years ago Code_Manager_Model.php 4 years ago Code_Manager_Preview.php 4 years ago Code_Manager_Settings.php 4 years ago Code_Manager_Tabs.php 4 years ago Message_Box.php 4 years ago WP_List_Table.php 4 years ago
Code_Manager_Import_File.php
83 lines
1 <?php
2
3 namespace Code_Manager {
4
5 /**
6 * Class Code_Manager_Import_File
7 *
8 * Performs import, called from Code_Manager_Import.
9 *
10 * @author Peter Schulz
11 * @since 1.0.0
12 */
13 class Code_Manager_Import_File {
14
15 protected $file_pointer;
16
17 public function __construct( $file_path ) {
18 $this->file_pointer = fopen( $file_path, 'rb' );
19 }
20
21 public function __destruct() {
22 fclose( $this->file_pointer );
23 }
24
25 public function import() {
26 global $wpdb;
27
28 $suppress = $wpdb->suppress_errors();
29 $rows = 0;
30 $rows_failed = 0;
31
32 if ( false !== $this->file_pointer ) {
33 while ( ! feof( $this->file_pointer ) ) {
34 $sql = fgets( $this->file_pointer );
35 if ( '--' !== substr( $sql, 0, 2 ) ) {
36 if ( ";\n" === substr( $sql, -2 ) ) {
37 $rows ++;
38 // Write file content to array for security check
39 $dml_check = explode( ' ', substr( trim( $sql ), 0, 150 ) );
40 if ( ! isset( $dml_check[0] ) || ! isset( $dml_check[1] ) ) {
41 // No content.
42 $rows_failed ++;
43 } else {
44 // Check first two words (must be insert into, no other statements allowed)
45 if ( strtolower( $dml_check[0] . $dml_check[1] ) !== 'insertinto' ) {
46 // Only insert allowed
47 $rows_failed ++;
48 } else {
49 // Check table name (only insert into code manager table allowed)
50 if ( ! stristr( $dml_check[2], '{wp_prefix}' . Code_Manager_Model::BASE_TABLE_NAME ) ) {
51 $rows_failed ++;
52 } else {
53 // Insert row
54 if ( false === $wpdb->query( str_replace( '{wp_prefix}', $wpdb->prefix, $sql ) ) ) {
55 $rows_failed ++;
56 }
57 }
58 }
59 }
60 }
61 }
62 }
63 }
64
65 $wpdb->suppress_errors( $suppress );
66
67 $msg = "Imported " . ( $rows - $rows_failed ) . " rows";
68 if ( $rows_failed > 0 ) {
69 $msg .= " ($rows_failed failed).";
70 } else {
71 $msg .= ".";
72 }
73 $msg = new Message_Box(
74 [
75 'message_text' => $msg,
76 ]
77 );
78 $msg->box();
79 }
80
81 }
82
83 }