PluginProbe
Datafeedr API / 1.0.124
Datafeedr API v1.0.124
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 1.0.33 All 181 releases
datafeedr-api / classes / class-dfrapi-import.php

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

126 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' ), 60 );
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 API', 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 ) . ' &#8212; Datafeedr API</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.', DFRAPI_DOMAIN ) . '</p>';
61 echo '<p>' . __( 'You can import network and merchant data at the same time.', DFRAPI_DOMAIN ) . '</p>';
62 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>';
68 echo '.</p>';
69 }
70
71 function field_import_data_textarea() {
72 echo '<textarea rows="10" cols="100%" name="' . $this->key . '[data]"></textarea></p>';
73 echo '<p class="description">' . __( 'Paste the exported data into the box, then click [Import Data].' ) . '</p>';
74 }
75
76 function validate( $input ) {
77 if ( isset( $input ) && is_array( $input ) && !empty( $input ) ) {
78 foreach( $input as $key => $value ) {
79 if ( $key == 'data' && ( strlen( $value ) > 16 ) ) {
80 $this->import_data( $value );
81 }
82 }
83 }
84 }
85
86 function import_data( $value ) {
87
88 // Import networks
89 preg_match ("/(\[NETWORKS\]).*(\[\/NETWORKS\])/i", $value, $networks);
90 if ( isset( $networks[0] ) ) {
91 $networks = str_replace( array("[NETWORKS]", "[/NETWORKS]"), "", $networks[0]);
92 $networks = trim( $networks );
93 if ( strlen( $networks ) > 1 ) {
94 update_option( 'dfrapi_networks', unserialize( $networks ) );
95 }
96 }
97
98 // Import merchants
99 preg_match ("/(\[MERCHANTS\]).*(\[\/MERCHANTS\])/i", $value, $merchants);
100 if ( isset( $merchants[0] ) ) {
101 $merchants = str_replace( array("[MERCHANTS]", "[/MERCHANTS]"), "", $merchants[0] );
102 $merchants = trim( $merchants );
103 if ( strlen( $merchants ) > 1 ) {
104 update_option( 'dfrapi_merchants', unserialize( $merchants ) );
105 }
106 }
107
108 }
109
110
111 } // class Dfrapi_Import
112
113 } // class_exists check
114
115
116
117
118
119
120
121
122
123
124
125
126