PluginProbe
Datafeedr API / 1.4.3
Datafeedr API v1.4.3
1.4.3 1.4.2 1.0.125 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.29 1.0.3 1.0.30 1.0.31 1.0.32 All 182 releases
← All changes | classes/class-dfrapi-import.php +50 -43 1.0.14 → 1.4.3 View file →
@@ -13,29 +13,27 @@
13 13 private $key;
14 14
15 15 public function __construct() {
16 16 $this->key = 'dfrapi_import';
17 - add_action( 'admin_init', array( &$this, 'register_settings' ) );
18 - add_action( 'admin_menu', array( $this, 'admin_menu' ) );
19 - add_action( 'admin_notices', array( $this, 'admin_notice' ) );
17 + add_action( 'admin_init', array( $this, 'register_settings' ) );
18 + add_action( 'admin_menu', array( $this, 'admin_menu' ), 60 );
19 + add_action( 'admin_notices', array( $this, 'admin_notice' ) );
20 20 }
21 -
21 +
22 22 function admin_menu() {
23 23 add_submenu_page(
24 24 'dfrapi',
25 - __( 'Import — Datafeedr API', DFRAPI_DOMAIN ),
26 - __( 'Import', DFRAPI_DOMAIN ),
25 + __( 'Import — Datafeedr API', 'datafeedr-api' ),
26 + __( 'Import', 'datafeedr-api' ),
27 27 'manage_options',
28 28 $this->key,
29 29 array( $this, 'output' )
30 30 );
31 31 }
32 -
32 +
33 33 function admin_notice() {
34 34 if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true && isset( $_GET['page'] ) && $this->key == $_GET['page'] ) {
35 - echo '<div class="updated"><p>';
36 - _e( 'Settings successfully imported!', DFRAPI_DOMAIN );
37 - echo '</p></div>';
35 + dfrapi_admin_notice( __( 'Settings successfully imported!', 'datafeedr-api' ), 'success' );
38 36 }
39 37 }
40 38
41 39 function output() {
@@ -44,28 +42,28 @@
44 42 echo '<form method="post" action="options.php">';
45 43 wp_nonce_field( 'update-options' );
46 44 settings_fields( $this->page );
47 45 do_settings_sections( $this->page);
48 - submit_button( __( 'Import Data', DFRAPI_DOMAIN ) );
49 - echo '</form>';
46 + submit_button( __( 'Import Data', 'datafeedr-api' ) );
47 + echo '</form>';
50 48 echo '</div>';
51 49 }
52 -
50 +
53 51 function register_settings() {
54 52 register_setting( $this->page, $this->key, array( $this, 'validate' ) );
55 - add_settings_section( 'import_data', __( 'Import Data', DFRAPI_DOMAIN ), array( &$this, 'section_import_data_desc' ), $this->page );
56 - add_settings_field( 'import_data_textarea', __( 'Data to Import', DFRAPI_DOMAIN ), array( &$this, 'field_import_data_textarea' ), $this->page, 'import_data' );
53 + add_settings_section( 'import_data', __( 'Import Data', 'datafeedr-api' ), array( &$this, 'section_import_data_desc' ), $this->page );
54 + add_settings_field( 'import_data_textarea', __( 'Data to Import', 'datafeedr-api' ), array( &$this, 'field_import_data_textarea' ), $this->page, 'import_data' );
57 55 }
58 -
56 +
59 57 function section_import_data_desc() {
60 - echo '<p>' . __( 'Import data from another website when you want to use the same selection of networks and/or merchants as you have already configured on another website.', DFRAPI_DOMAIN ) . '</p>';
61 - echo '<p>' . __( 'You can import network and merchant data at the same time.', DFRAPI_DOMAIN ) . '</p>';
58 + echo '<p>' . __( 'Import data from another website when you want to use the same selection of networks and/or merchants as you have already configured on another website.', 'datafeedr-api' ) . '</p>';
59 + echo '<p>' . __( 'You can import network and merchant data at the same time.', 'datafeedr-api' ) . '</p>';
62 60 echo '<p class="dfrapi_warning">';
63 - echo '<strong>' . __( 'WARNING: ', DFRAPI_DOMAIN ) . '</strong> ';
64 - echo __( 'Importing will overwrite all of your current ', DFRAPI_DOMAIN );
65 - echo ' <a href="' . admin_url( 'admin.php?page=dfrapi_networks' ) . '">'. __( 'network settings', DFRAPI_DOMAIN ) . '</a>';
66 - echo __( ' and/or ', DFRAPI_DOMAIN );
67 - echo ' <a href="' . admin_url( 'admin.php?page=dfrapi_merchants' ) . '">'. __( 'merchant settings', DFRAPI_DOMAIN ) . '</a>';
61 + echo '<strong>' . __( 'WARNING: ', 'datafeedr-api' ) . '</strong> ';
62 + echo __( 'Importing will overwrite all of your current ', 'datafeedr-api' );
63 + echo ' <a href="' . admin_url( 'admin.php?page=dfrapi_networks' ) . '">'. __( 'network settings', 'datafeedr-api' ) . '</a>';
64 + echo __( ' and/or ', 'datafeedr-api' );
65 + echo ' <a href="' . admin_url( 'admin.php?page=dfrapi_merchants' ) . '">'. __( 'merchant settings', 'datafeedr-api' ) . '</a>';
68 66 echo '.</p>';
69 67 }
70 68
71 69 function field_import_data_textarea() {
@@ -71,9 +69,9 @@
71 69 function field_import_data_textarea() {
72 70 echo '<textarea rows="10" cols="100%" name="' . $this->key . '[data]"></textarea></p>';
73 71 echo '<p class="description">' . __( 'Paste the exported data into the box, then click [Import Data].' ) . '</p>';
74 72 }
75 -
73 +
76 74 function validate( $input ) {
77 75 if ( isset( $input ) && is_array( $input ) && !empty( $input ) ) {
78 76 foreach( $input as $key => $value ) {
79 77 if ( $key == 'data' && ( strlen( $value ) > 16 ) ) {
@@ -81,45 +79,54 @@
81 79 }
82 80 }
83 81 }
84 82 }
85 -
83 +
86 84 function import_data( $value ) {
87 -
85 +
88 86 // Import networks
89 87 preg_match ("/(\[NETWORKS\]).*(\[\/NETWORKS\])/i", $value, $networks);
90 88 if ( isset( $networks[0] ) ) {
91 89 $networks = str_replace( array("[NETWORKS]", "[/NETWORKS]"), "", $networks[0]);
92 90 $networks = trim( $networks );
93 - if ( strlen( $networks ) > 1 ) {
94 - update_option( 'dfrapi_networks', unserialize( $networks ) );
91 + $networks = $this->unserialize_data( $networks );
92 + if ( is_array( $networks ) ) {
93 + update_option( 'dfrapi_networks', dfrapi_sanitize_networks_option( $networks ) );
95 94 }
96 95 }
97 -
96 +
98 97 // Import merchants
99 98 preg_match ("/(\[MERCHANTS\]).*(\[\/MERCHANTS\])/i", $value, $merchants);
100 99 if ( isset( $merchants[0] ) ) {
101 100 $merchants = str_replace( array("[MERCHANTS]", "[/MERCHANTS]"), "", $merchants[0] );
102 101 $merchants = trim( $merchants );
103 - if ( strlen( $merchants ) > 1 ) {
104 - update_option( 'dfrapi_merchants', unserialize( $merchants ) );
102 + $merchants = $this->unserialize_data( $merchants );
103 + if ( is_array( $merchants ) ) {
104 + update_option( 'dfrapi_merchants', dfrapi_sanitize_merchants_option( $merchants ) );
105 105 }
106 106 }
107 -
107 +
108 108 }
109 -
110 -
111 - } // class Dfrapi_Import
112 109
113 -} // class_exists check
110 + /**
111 + * Safely unserializes exported data. Objects are never instantiated.
112 + *
113 + * @since 1.4.3
114 + *
115 + * @param string $data
116 + *
117 + * @return array|null Array on success, null if $data is not a serialized array.
118 + */
119 + private function unserialize_data( $data ) {
114 120
121 + if ( strlen( $data ) <= 1 || ! is_serialized( $data ) ) {
122 + return null;
123 + }
115 124
125 + $value = @unserialize( $data, [ 'allowed_classes' => false ] );
116 126
127 + return is_array( $value ) ? $value : null;
128 + }
117 129
130 + } // class Dfrapi_Import
118 131
119 -
120 -
121 -
122 -
123 -
124 -
125 -
132 +} // class_exists check