PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.43
Code Manager v1.0.43
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 11 months ago Code_Manager_Dashboard.php 11 months ago Code_Manager_Export.php 11 months ago Code_Manager_Form.php 11 months ago Code_Manager_Import.php 11 months ago Code_Manager_Import_File.php 11 months ago Code_Manager_List.php 11 months ago Code_Manager_List_View.php 11 months ago Code_Manager_Model.php 11 months ago Code_Manager_Preview.php 11 months ago Code_Manager_Settings.php 11 months ago Code_Manager_Tabs.php 11 months ago Message_Box.php 11 months ago WP_List_Table.php 11 months ago
Code_Manager_Import_File.php
105 lines
1 <?php
2 /**
3 * Code Manager file import
4 *
5 * @package Code_Manager
6 */
7
8 namespace Code_Manager {
9
10 /**
11 * Class Code_Manager_Import_File
12 *
13 * Performs import, called from Code_Manager_Import.
14 *
15 * @author Peter Schulz
16 * @since 1.0.0
17 */
18 class Code_Manager_Import_File {
19
20 /**
21 * File pointer
22 *
23 * @var false|resource
24 */
25 protected $file_pointer;
26
27 /**
28 * Constructor
29 *
30 * @param string $file_path Full file path.
31 */
32 public function __construct( $file_path ) {
33 $this->file_pointer = fopen( $file_path, 'rb' );
34 }
35
36 /**
37 * Close file
38 */
39 public function __destruct() {
40 fclose( $this->file_pointer );
41 }
42
43 /**
44 * Import file
45 */
46 public function import() {
47 global $wpdb;
48
49 $suppress = $wpdb->suppress_errors();
50 $rows = 0;
51 $rows_failed = 0;
52
53 if ( false !== $this->file_pointer ) {
54 while ( ! feof( $this->file_pointer ) ) {
55 $sql = fgets( $this->file_pointer );
56 if ( '--' !== substr( $sql, 0, 2 ) ) {
57 if ( ";\n" === substr( $sql, -2 ) ) {
58 $rows ++;
59 // Write file content to array for security check.
60 $dml_check = explode( ' ', substr( trim( $sql ), 0, 150 ) );
61 if ( ! isset( $dml_check[0] ) || ! isset( $dml_check[1] ) ) {
62 // No content.
63 $rows_failed ++;
64 } else {
65 // Check first two words (must be insert into, no other statements allowed).
66 if ( strtolower( $dml_check[0] . $dml_check[1] ) !== 'insertinto' ) {
67 // Only insert allowed.
68 $rows_failed ++;
69 } else {
70 // Check table name (only insert into code manager table allowed).
71 if ( ! stristr( $dml_check[2], '{wp_prefix}' . Code_Manager_Model::BASE_TABLE_NAME ) ) {
72 $rows_failed ++;
73 } else {
74 // Insert row.
75 if ( false === $wpdb->query( str_replace( '{wp_prefix}', $wpdb->prefix, $sql ) ) ) {
76 $rows_failed ++;
77 }
78 }
79 }
80 }
81 }
82 }
83 }
84 }
85
86 $wpdb->suppress_errors( $suppress );
87
88 $msg = 'Imported ' . ( $rows - $rows_failed ) . ' rows';
89 if ( $rows_failed > 0 ) {
90 $msg .= " ($rows_failed failed).";
91 } else {
92 $msg .= '.';
93 }
94 $msg = new Message_Box(
95 array(
96 'message_text' => $msg,
97 )
98 );
99 $msg->box();
100 }
101
102 }
103
104 }
105