PluginProbe
Datafeedr API / 1.4.0
Datafeedr API v1.4.0
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.4.0, at classes/class-dfrapi-import.php

111 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', 'datafeedr-api' ),
26 __( 'Import', 'datafeedr-api' ),
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 dfrapi_admin_notice( __( 'Settings successfully imported!', 'datafeedr-api' ), 'success' );
36 }
37 }
38
39 function output() {
40 echo '<div class="wrap" id="' . $this->key . '">';
41 echo '<h2>' . dfrapi_setting_pages( $this->page ) . ' &#8212; Datafeedr API</h2>';
42 echo '<form method="post" action="options.php">';
43 wp_nonce_field( 'update-options' );
44 settings_fields( $this->page );
45 do_settings_sections( $this->page);
46 submit_button( __( 'Import Data', 'datafeedr-api' ) );
47 echo '</form>';
48 echo '</div>';
49 }
50
51 function register_settings() {
52 register_setting( $this->page, $this->key, array( $this, 'validate' ) );
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' );
55 }
56
57 function section_import_data_desc() {
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>';
60 echo '<p class="dfrapi_warning">';
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>';
66 echo '.</p>';
67 }
68
69 function field_import_data_textarea() {
70 echo '<textarea rows="10" cols="100%" name="' . $this->key . '[data]"></textarea></p>';
71 echo '<p class="description">' . __( 'Paste the exported data into the box, then click [Import Data].' ) . '</p>';
72 }
73
74 function validate( $input ) {
75 if ( isset( $input ) && is_array( $input ) && !empty( $input ) ) {
76 foreach( $input as $key => $value ) {
77 if ( $key == 'data' && ( strlen( $value ) > 16 ) ) {
78 $this->import_data( $value );
79 }
80 }
81 }
82 }
83
84 function import_data( $value ) {
85
86 // Import networks
87 preg_match ("/(\[NETWORKS\]).*(\[\/NETWORKS\])/i", $value, $networks);
88 if ( isset( $networks[0] ) ) {
89 $networks = str_replace( array("[NETWORKS]", "[/NETWORKS]"), "", $networks[0]);
90 $networks = trim( $networks );
91 if ( strlen( $networks ) > 1 ) {
92 update_option( 'dfrapi_networks', unserialize( $networks ) );
93 }
94 }
95
96 // Import merchants
97 preg_match ("/(\[MERCHANTS\]).*(\[\/MERCHANTS\])/i", $value, $merchants);
98 if ( isset( $merchants[0] ) ) {
99 $merchants = str_replace( array("[MERCHANTS]", "[/MERCHANTS]"), "", $merchants[0] );
100 $merchants = trim( $merchants );
101 if ( strlen( $merchants ) > 1 ) {
102 update_option( 'dfrapi_merchants', unserialize( $merchants ) );
103 }
104 }
105
106 }
107
108 } // class Dfrapi_Import
109
110 } // class_exists check
111