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 +52 -44 1.0.3 → 1.4.3 View file →
@@ -13,66 +13,65 @@
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 Product Sets', 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() {
42 40 echo '<div class="wrap" id="' . $this->key . '">';
43 - echo '<h2>' . dfrapi_setting_pages( $this->page ) . '</h2>';
41 + echo '<h2>' . dfrapi_setting_pages( $this->page ) . ' &#8212; Datafeedr API</h2>';
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. 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>';
61 60 echo '<p class="dfrapi_warning">';
62 - echo '<strong>' . __( 'WARNING: ', DFRAPI_DOMAIN ) . '</strong> ';
63 - echo __( 'Importing will overwrite all of your current ', DFRAPI_DOMAIN );
64 - echo ' <a href="' . admin_url( 'admin.php?page=dfrapi_networks' ) . '">'. __( 'network settings', DFRAPI_DOMAIN ) . '</a>';
65 - echo __( ' and/or ', DFRAPI_DOMAIN );
66 - 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>';
67 66 echo '.</p>';
68 67 }
69 68
70 69 function field_import_data_textarea() {
71 70 echo '<textarea rows="10" cols="100%" name="' . $this->key . '[data]"></textarea></p>';
72 - echo '<p class="description">' . __( 'Paste the exported data into the box, then click [Import Data]. You can import Network and Merchant data at the same time.' ) . '</p>';
71 + echo '<p class="description">' . __( 'Paste the exported data into the box, then click [Import Data].' ) . '</p>';
73 72 }
74 -
73 +
75 74 function validate( $input ) {
76 75 if ( isset( $input ) && is_array( $input ) && !empty( $input ) ) {
77 76 foreach( $input as $key => $value ) {
78 77 if ( $key == 'data' && ( strlen( $value ) > 16 ) ) {
@@ -80,45 +79,54 @@
80 79 }
81 80 }
82 81 }
83 82 }
84 -
83 +
85 84 function import_data( $value ) {
86 -
85 +
87 86 // Import networks
88 87 preg_match ("/(\[NETWORKS\]).*(\[\/NETWORKS\])/i", $value, $networks);
89 88 if ( isset( $networks[0] ) ) {
90 89 $networks = str_replace( array("[NETWORKS]", "[/NETWORKS]"), "", $networks[0]);
91 90 $networks = trim( $networks );
92 - if ( strlen( $networks ) > 1 ) {
93 - 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 ) );
94 94 }
95 95 }
96 -
96 +
97 97 // Import merchants
98 98 preg_match ("/(\[MERCHANTS\]).*(\[\/MERCHANTS\])/i", $value, $merchants);
99 99 if ( isset( $merchants[0] ) ) {
100 100 $merchants = str_replace( array("[MERCHANTS]", "[/MERCHANTS]"), "", $merchants[0] );
101 101 $merchants = trim( $merchants );
102 - if ( strlen( $merchants ) > 1 ) {
103 - 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 ) );
104 105 }
105 106 }
106 -
107 +
107 108 }
108 -
109 -
110 - } // class Dfrapi_Import
111 109
112 -} // 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 ) {
113 120
121 + if ( strlen( $data ) <= 1 || ! is_serialized( $data ) ) {
122 + return null;
123 + }
114 124
125 + $value = @unserialize( $data, [ 'allowed_classes' => false ] );
115 126
127 + return is_array( $value ) ? $value : null;
128 + }
116 129
130 + } // class Dfrapi_Import
117 131
118 -
119 -
120 -
121 -
122 -
123 -
124 -
132 +} // class_exists check