PluginProbe
Datafeedr API / 1.0.3
Datafeedr API v1.0.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
datafeedr-api / classes / class-dfrapi-import.php

class-dfrapi-import.php in Datafeedr API 1.0.3, at classes/class-dfrapi-import.php

125 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 if ( ! class_exists( 'Dfrapi_Import' ) ) {
6
7 /**
8 * Configuration page.
9 */
10 class Dfrapi_Import {
11
12 private $page = 'dfrapi-import';
13 private $key;
14
15 public function __construct() {
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' ) );
20 }
21
22 function admin_menu() {
23 add_submenu_page(
24 'dfrapi',
25 __( 'Import &#8212; Datafeedr Product Sets', DFRAPI_DOMAIN ),
26 __( 'Import', DFRAPI_DOMAIN ),
27 'manage_options',
28 $this->key,
29 array( $this, 'output' )
30 );
31 }
32
33 function admin_notice() {
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>';
38 }
39 }
40
41 function output() {
42 echo '<div class="wrap" id="' . $this->key . '">';
43 echo '<h2>' . dfrapi_setting_pages( $this->page ) . '</h2>';
44 echo '<form method="post" action="options.php">';
45 wp_nonce_field( 'update-options' );
46 settings_fields( $this->page );
47 do_settings_sections( $this->page);
48 submit_button( __( 'Import Data', DFRAPI_DOMAIN ) );
49 echo '</form>';
50 echo '</div>';
51 }
52
53 function register_settings() {
54 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' );
57 }
58
59 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>';
61 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>';
67 echo '.</p>';
68 }
69
70 function field_import_data_textarea() {
71 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>';
73 }
74
75 function validate( $input ) {
76 if ( isset( $input ) && is_array( $input ) && !empty( $input ) ) {
77 foreach( $input as $key => $value ) {
78 if ( $key == 'data' && ( strlen( $value ) > 16 ) ) {
79 $this->import_data( $value );
80 }
81 }
82 }
83 }
84
85 function import_data( $value ) {
86
87 // Import networks
88 preg_match ("/(\[NETWORKS\]).*(\[\/NETWORKS\])/i", $value, $networks);
89 if ( isset( $networks[0] ) ) {
90 $networks = str_replace( array("[NETWORKS]", "[/NETWORKS]"), "", $networks[0]);
91 $networks = trim( $networks );
92 if ( strlen( $networks ) > 1 ) {
93 update_option( 'dfrapi_networks', unserialize( $networks ) );
94 }
95 }
96
97 // Import merchants
98 preg_match ("/(\[MERCHANTS\]).*(\[\/MERCHANTS\])/i", $value, $merchants);
99 if ( isset( $merchants[0] ) ) {
100 $merchants = str_replace( array("[MERCHANTS]", "[/MERCHANTS]"), "", $merchants[0] );
101 $merchants = trim( $merchants );
102 if ( strlen( $merchants ) > 1 ) {
103 update_option( 'dfrapi_merchants', unserialize( $merchants ) );
104 }
105 }
106
107 }
108
109
110 } // class Dfrapi_Import
111
112 } // class_exists check
113
114
115
116
117
118
119
120
121
122
123
124
125