Rara One Click Demo Import - Version 1.0.5

Version Description

  • RARA THEME DEPENDENT
Download this release

Release Info

Developer raratheme
Plugin Icon 128x128 Rara One Click Demo Import
Version 1.0.5
Comparing to
See all releases

Code changes from version 1.0.2 to 1.0.5

assets/css/style.css CHANGED
@@ -106,4 +106,43 @@
106
  float: none;
107
  visibility: visible;
108
  margin-bottom: 6px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  }
106
  float: none;
107
  visibility: visible;
108
  margin-bottom: 6px;
109
+ }
110
+
111
+ #tabs-container .tabs-menu{
112
+ margin: 0;
113
+ padding: 0;
114
+ list-style: none;
115
+ overflow: hidden;
116
+ text-transform: capitalize;
117
+ }
118
+
119
+ #tabs-container .tabs-menu li{
120
+ float: left;
121
+ border: 1px solid transparent;
122
+ margin: 0;
123
+ }
124
+
125
+ #tabs-container .tabs-menu li.current{
126
+ border: 1px solid #ddd;
127
+ background: #fff;
128
+ border-bottom: 1px solid transparent;
129
+ }
130
+
131
+ #tabs-container .tabs-menu li a{
132
+ text-decoration: none;
133
+ color: #444;
134
+ display: block;
135
+ padding: 3px 5px 6px;
136
+ }
137
+
138
+ #tabs-container .tabs-menu li a:focus{
139
+ box-shadow: none;
140
+ }
141
+
142
+ #tabs-container .tab-content{
143
+ background: #fff;
144
+ padding: 10px .9em;
145
+ display: none;
146
+ border: 1px solid #ddd;
147
+ margin-top: -1px;
148
  }
assets/js/script.js CHANGED
@@ -75,4 +75,31 @@ jQuery( function ( $ ) {
75
  $( '.js-rrdi-demo-import-notice' ).html( currentImportNotice );
76
  });
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  });
75
  $( '.js-rrdi-demo-import-notice' ).html( currentImportNotice );
76
  });
77
 
78
+ $('.tabs-menu a').click(function(event) {
79
+ event.preventDefault();
80
+ $(this).parent().addClass('current');
81
+ $(this).parent().siblings().removeClass('current');
82
+ var tab = $(this).attr('href');
83
+ $('.tab-content').not(tab).css('display', 'none');
84
+ $('#'+tab).show();
85
+ });
86
+
87
+ var uploadViewToggle = $( '.upload-view-toggle' ),
88
+ $body = $( document.body );
89
+ uploadViewToggle.on( 'click', function() {
90
+ // Toggle the upload view.
91
+ $body.toggleClass( 'show-upload-view' );
92
+ // Toggle the `aria-expanded` button attribute.
93
+ uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) );
94
+ });
95
+ $('.tabs-menu a').click(function(event) {
96
+ if( $(this).attr('href') != 'welcome')
97
+ {
98
+ $('.upload-view-toggle').hide();
99
+ }
100
+ else{
101
+ $('.upload-view-toggle').show();
102
+ }
103
+ });
104
+
105
  });
includes/class-rrdi-init.php CHANGED
@@ -27,7 +27,14 @@ class RDDI_init
27
  add_action( 'admin_notices', 'rrdi_old_php_admin_error_notice' );
28
  }
29
  else {
30
-
 
 
 
 
 
 
 
31
  // Require main plugin file.
32
  require RRDI_PATH . 'includes/class-rrdi-main.php';
33
 
27
  add_action( 'admin_notices', 'rrdi_old_php_admin_error_notice' );
28
  }
29
  else {
30
+
31
+ $upload = wp_upload_dir();
32
+ $upload_dir = $upload['basedir'];
33
+ $upload_dir = $upload_dir . '/rara-demo-pack';
34
+ if (! is_dir($upload_dir)) {
35
+ mkdir( $upload_dir, 0755 );
36
+ }
37
+
38
  // Require main plugin file.
39
  require RRDI_PATH . 'includes/class-rrdi-main.php';
40
 
includes/class-rrdi-main.php CHANGED
@@ -9,6 +9,20 @@
9
  */
10
  class RRDI_Theme_Demo_Import {
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  /**
13
  * @var $instance the reference to *Singleton* instance of this class
14
  */
@@ -42,14 +56,90 @@ class RRDI_Theme_Demo_Import {
42
  protected function __construct() {
43
  require RRDI_PATH . 'includes/class-rrdi-include-files.php';
44
  // Actions.
45
- add_action( 'admin_menu', array( $this, 'create_plugin_page' ) );
 
 
 
 
 
 
 
 
 
 
46
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
47
  add_action( 'wp_ajax_rrdi_import_demo_data', array( $this, 'rrdi_import_demo_data_ajax_callback' ) );
48
- add_action( 'after_setup_theme', array( $this, 'setup_plugin_with_filter_data' ) );
49
  add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  }
51
 
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  /**
54
  * Private clone method to prevent cloning of the instance of the *Singleton* instance.
55
  *
@@ -82,168 +172,170 @@ class RRDI_Theme_Demo_Import {
82
  $this->plugin_page = add_submenu_page( $plugin_page_setup['parent_slug'], $plugin_page_setup['page_title'], $plugin_page_setup['menu_title'], $plugin_page_setup['capability'], $plugin_page_setup['menu_slug'], array( $this, 'display_plugin_page' ) );
83
  }
84
 
85
-
86
  /**
87
- * Plugin page display.
88
- */
89
- public function display_plugin_page() {
90
- ?>
91
-
92
- <div class="RRDI__intro-notice notice notice-warning is-dismissible">
93
- <p><?php $msg = __( 'Before you begin, make sure all the required plugins are activated.', 'rara-one-click-demo-import' ); echo apply_filters( 'rrdi_before_import_msg', $msg); ?>
94
- </p>
95
- </div>
96
-
97
- <div class="rrdi wrap about-wrap">
98
-
99
- <h1><?php esc_html_e( 'Rara One Click Demo Import', 'rara-one-click-demo-import' ); ?></h1>
100
-
101
- <?php
102
-
103
- // Display warrning if PHP safe mode is enabled, since we wont be able to change the max_execution_time.
104
- if ( ini_get( 'safe_mode' ) ) {
105
- printf(
106
- esc_html__( '%sWarning: your server is using %sPHP safe mode%s. This means that you might experience server timeout errors.%s', 'rara-one-click-demo-import' ),
107
- '<div class="notice notice-warning is-dismissible"><p>',
108
- '<strong>',
109
- '</strong>',
110
- '</p></div>'
111
- );
112
  }
113
 
114
- // Start output buffer for displaying the plugin intro text.
115
- ob_start();
116
- ?>
117
-
118
- <div class="RRDI__intro-text">
119
-
120
- <p class="about-description">
121
- <?php $msg = esc_html__( 'Upload your theme’s live demo content and settings with a click. If your theme comes with the demo content bundled with it, just click “Import Now” button. Otherwise, select files to import and click “Import Now”. As simple as that.', 'rara-one-click-demo-import' ); echo apply_filters( 'rrdi_import_instruction',$msg ); ?>
122
- </p>
123
-
124
- <h3><?php esc_html_e( 'The following data will be imported:', 'rara-one-click-demo-import' ); ?></h3>
125
-
126
- <ul>
127
- <li><?php esc_html_e( 'Posts', 'rara-one-click-demo-import' ); ?></li>
128
- <li><?php esc_html_e( 'Pages', 'rara-one-click-demo-import' ); ?></li>
129
- <li><?php esc_html_e( 'Images', 'rara-one-click-demo-import' ); ?></li>
130
- <li><?php esc_html_e( 'Widgets', 'rara-one-click-demo-import' ); ?></li>
131
- <li><?php esc_html_e( 'Menus', 'rara-one-click-demo-import' ); ?></li>
132
- <li><?php esc_html_e( 'Settings', 'rara-one-click-demo-import' ); ?></li>
133
- </ul>
134
 
135
- <p><b><?php $msg = __( 'NOTE: Please import the demo content only on fresh WordPress installation. You can reset your WordPress Installation using any reset plugin like WP Reset by WP Dev.','rara-one-click-demo-import' ); echo apply_filters( 'rrdi_fresh_install_instruction',$msg );?></b></p>
136
 
137
- <hr>
 
 
 
138
 
139
- </div>
140
-
141
- <?php
142
- $plugin_intro_text = ob_get_clean();
143
-
144
- // Display the plugin intro text (can be replaced with custom text through the filter below).
145
- echo wp_kses_post( apply_filters( 'rrdi/plugin_intro_text', $plugin_intro_text ) );
146
- ?>
147
 
 
 
148
 
149
- <?php if ( empty( $this->import_files ) ) : ?>
 
 
 
150
 
151
- <div class="notice notice-info is-dismissible">
152
- <p><?php esc_html_e( 'No predefined import files are available in this theme. Please upload the import files manually.', 'rara-one-click-demo-import' ); ?></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  </div>
 
 
 
 
154
 
155
- <div class="RRDI__file-upload-container">
156
-
157
- <h2><?php esc_html_e( 'Please, select the following files.', 'rara-one-click-demo-import' ); ?></h2>
158
-
159
- <div class="RRDI__file-upload">
160
- <h3><label for="content-file-upload"><?php esc_html_e( 'Choose a XML file for content import:', 'rara-one-click-demo-import' ); ?></label></h3>
161
- <input id="RRDI__content-file-upload" type="file" name="content-file-upload">
162
- </div>
163
-
164
- <div class="RRDI__file-upload">
165
- <h3><label for="widget-file-upload"><?php esc_html_e( 'Choose a WIE or JSON file for widget import:', 'rara-one-click-demo-import' ); ?></label> <span><?php esc_html_e( '(*optional)', 'rara-one-click-demo-import' ); ?></span></h3>
166
- <input id="RRDI__widget-file-upload" type="file" name="widget-file-upload">
167
- </div>
168
-
169
- <div class="RRDI__file-upload">
170
- <h3><label for="customizer-file-upload"><?php esc_html_e( 'Choose a DAT file for customizer import:', 'rara-one-click-demo-import' ); ?></label> <span><?php esc_html_e( '(*optional)', 'rara-one-click-demo-import' ); ?></span></h3>
171
- <input id="RRDI__customizer-file-upload" type="file" name="customizer-file-upload">
172
- </div>
173
-
174
- </div>
175
 
176
- <?php elseif ( 1 < count( $this->import_files ) ) : ?>
 
 
 
 
 
 
 
177
 
178
- <div class="RRDI__multi-select-import">
 
 
179
 
180
- <h2><?php esc_html_e( 'Choose which demo you want to import:', 'rara-one-click-demo-import' ); ?></h2>
 
 
 
181
 
182
- <select id="RRDI__demo-import-files" class="RRDI__demo-import-files">
183
- <?php foreach ( $this->import_files as $index => $import_file ) : ?>
184
- <option value="<?php echo esc_attr( $index ); ?>">
185
- <?php echo esc_html( $import_file['import_file_name'] ); ?>
186
- </option>
187
- <?php endforeach; ?>
188
- </select>
189
 
190
- <?php
191
- // Check if at least one preview image is defined, so we can prepare the structure for display.
192
- $preview_image_is_defined = false;
193
- foreach ( $this->import_files as $import_file ) {
194
- if ( isset( $import_file['import_preview_image_url'] ) ) {
195
- $preview_image_is_defined = true;
196
- break;
197
- }
198
  }
199
 
200
- if ( $preview_image_is_defined ) :
201
- ?>
202
-
203
- <div class="RRDI__demo-import-preview-container">
204
-
205
- <p><?php esc_html_e( 'Import preview:', 'rara-one-click-demo-import' ); ?></p>
206
-
207
- <p class="RRDI__demo-import-preview-image-message js-rrdi-preview-image-message"><?php
208
- if ( ! isset( $this->import_files[0]['import_preview_image_url'] ) ) {
209
- esc_html_e( 'No preview image defined for this import.', 'rara-one-click-demo-import' );
210
- }
211
- // Leave the img tag below and the p tag above available for later changes via JS.
212
- ?></p>
213
-
214
- <img id="RRDI__demo-import-preview-image" class="js-rrdi-preview-image" src="<?php echo ! empty( $this->import_files[0]['import_preview_image_url'] ) ? esc_url( $this->import_files[0]['import_preview_image_url'] ) : ''; ?>">
215
-
216
- </div>
217
-
218
- <?php endif; ?>
219
-
220
- </div>
221
-
222
- <?php endif; ?>
223
 
224
- <div class="RRDI__demo-import-notice js-rrdi-demo-import-notice"><?php
225
- if ( is_array( $this->import_files ) && ! empty( $this->import_files[0]['import_notice'] ) ) {
226
- echo wp_kses_post( $this->import_files[0]['import_notice'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  }
228
- ?></div>
229
-
230
- <p class="RRDI__button-container">
231
- <button class="RRDI__button button button-hero button-primary js-rrdi-import-data"><?php esc_html_e( 'Import Now', 'rara-one-click-demo-import' ); ?></button>
232
- <span><?php esc_html_e( 'Click the button to beign the importing process. Please be patient, the process might take a few minutes.', 'rara-one-click-demo-import' ); ?></span>
233
- </p>
234
-
235
- <p class="RRDI__ajax-loader js-rrdi-ajax-loader">
236
- <span class="spinner"></span> <?php esc_html_e( 'Importing now, please wait!', 'rara-one-click-demo-import' ); ?>
237
- </p>
238
-
239
- <div class="RRDI__response js-rrdi-ajax-response"></div>
240
-
241
- </div>
242
 
243
- <?php
 
 
 
 
 
 
 
 
 
244
  }
245
-
246
-
247
  /**
248
  * Enqueue admin scripts (JS and CSS)
249
  *
@@ -265,7 +357,6 @@ class RRDI_Theme_Demo_Import {
265
  ),
266
  )
267
  );
268
-
269
  wp_enqueue_style( 'rrdi-main-css', RRDI_URL . 'assets/css/style.css', array() , RRDI_VERSION );
270
  }
271
  }
9
  */
10
  class RRDI_Theme_Demo_Import {
11
 
12
+ public $demo_config;
13
+
14
+ /**
15
+ * Demo packages.
16
+ * @var array
17
+ */
18
+ public $demo_packages;
19
+
20
+ /**
21
+ * Demo installer.
22
+ * @var bool
23
+ */
24
+ public $demo_installer = true;
25
+
26
  /**
27
  * @var $instance the reference to *Singleton* instance of this class
28
  */
56
  protected function __construct() {
57
  require RRDI_PATH . 'includes/class-rrdi-include-files.php';
58
  // Actions.
59
+
60
+ $this->includes();
61
+
62
+
63
+ add_action( 'init', array( $this, 'setup' ), 5 );
64
+ $get_theme = wp_get_theme();
65
+
66
+ if( $get_theme->get( 'AuthorURI' ) == 'http://raratheme.com/' || $get_theme->get( 'AuthorURI' ) == 'https://raratheme.com/' )
67
+ {
68
+ add_action( 'admin_menu', array( $this, 'create_plugin_page' ) );
69
+ }
70
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
71
  add_action( 'wp_ajax_rrdi_import_demo_data', array( $this, 'rrdi_import_demo_data_ajax_callback' ) );
72
+ add_action( 'init', array( $this, 'setup_plugin_with_filter_data' ) );
73
  add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
74
+ // AJAX Events to import demo and dismiss notice.
75
+ add_action( 'wp_ajax_dismiss-notice', array( $this, 'ajax_dismiss_notice' ) );
76
+ }
77
+
78
+ /**
79
+ * Demo importer setup.
80
+ */
81
+ public function setup() {
82
+ $this->demo_config = apply_filters( 'rara_demo_importer_config', array() );
83
+ $this->demo_packages = apply_filters( 'rara_demo_importer_packages', array() );
84
+ $this->demo_installer = apply_filters( 'rara_demo_importer_installer', true );
85
+ }
86
+
87
+
88
+ function getNewestDir($path) {
89
+ $working_dir = getcwd();
90
+ chdir($path); ## chdir to requested dir
91
+ $ret_val = false;
92
+ if ($p = opendir($path) ) {
93
+ while (false !== ($file = readdir($p))) {
94
+ if ($file{0} != '.' && is_dir($file)) {
95
+ $list[] = date('YmdHis', filemtime($path.'/'.$file)).$path.'/'.$file;
96
+ }
97
+ }
98
+ if( isset($list) )
99
+ {
100
+ rsort($list);
101
+ $ret_val = $list[0];
102
+ }
103
+ }
104
+ chdir($working_dir); ## chdir back to script's dir
105
+ return $ret_val;
106
+ }
107
+
108
+ function lreplace($search, $replace, $subject){
109
+ $pos = strrpos($subject, $search);
110
+ if($pos !== false){
111
+ $subject = substr_replace($subject, $replace, $pos, strlen($search));
112
+ }
113
+ return $subject;
114
  }
115
 
116
 
117
+
118
+ /**
119
+ * Includes.
120
+ */
121
+ private function includes() {
122
+ $upload_dir = wp_upload_dir();
123
+ // Check the folder contains at least 1 valid demo config.
124
+ $path = $upload_dir['basedir'] . '/rara-demo-pack/';
125
+ $newpath = $this->getNewestDir($path);
126
+
127
+ $haystack = $newpath;
128
+ $needle = "//";
129
+ $replace_with = "/";
130
+ $result = $this->lreplace($needle, $replace_with, $haystack);
131
+ $result = str_replace(' ', '', $result);
132
+ $result = preg_replace('/[0-9]+/', '', $result);
133
+ $files = glob( $result.'/import-hooks.php' );
134
+ if ( $files ) {
135
+ foreach ( $files as $file ) {
136
+ if ( $file && is_readable( $file ) ) {
137
+ include( $file );
138
+ }
139
+ }
140
+ }
141
+ }
142
+
143
  /**
144
  * Private clone method to prevent cloning of the instance of the *Singleton* instance.
145
  *
172
  $this->plugin_page = add_submenu_page( $plugin_page_setup['parent_slug'], $plugin_page_setup['page_title'], $plugin_page_setup['menu_title'], $plugin_page_setup['capability'], $plugin_page_setup['menu_slug'], array( $this, 'display_plugin_page' ) );
173
  }
174
 
 
175
  /**
176
+ * Settings Tabs.
177
+ *
178
+ * @since 1.0.4
179
+ */
180
+ function rrdi_settings_option_tabs() {
181
+
182
+ $options = array(
183
+ 'welcome' => 'welcome.php',
184
+ 'import_demo' => 'installed-demos.php',
185
+ );
186
+ $options = apply_filters( 'rrdi_settings_option_tabs', $options );
187
+ return $options;
188
+ }
189
+
190
+ private function rddi_upload_demo_pack() {
191
+ include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
192
+
193
+ if ( ! current_user_can( 'upload_files' ) ) {
194
+ wp_die( __( 'Sorry, you are not allowed to install demo on this site.', 'rara-one-click-demo-importer' ) );
 
 
 
 
 
 
195
  }
196
 
197
+ // check_admin_referer( 'demo-upload' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
+ $file_upload = new File_Upload_Upgrader( 'demozip', 'package' );
200
 
201
+ $title = sprintf( __( 'Installing Demo from uploaded file: %s', 'rara-one-click-demo-importer' ), esc_html( basename( $file_upload->filename ) ) );
202
+ $nonce = 'demo-upload';
203
+ $url = add_query_arg( array( 'package' => $file_upload->id ), 'themes.php?page=demo-importer&action=upload-demo' );
204
+ $type = 'upload'; // Install demo type, From Web or an Upload.
205
 
206
+ // Demo Upgrader Class.
207
+ include_once( dirname( __FILE__ ) . '/vendor/class-demo-upgrader.php' );
208
+ include_once( dirname( __FILE__ ) . '/vendor/class-demo-installer-skin.php' );
 
 
 
 
 
209
 
210
+ $upgrader = new RDDI_Demo_Upgrader( new RDDI_Demo_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
211
+ $result = $upgrader->install( $file_upload->package );
212
 
213
+ if ( $result || is_wp_error( $result ) ) {
214
+ $file_upload->cleanup();
215
+ }
216
+ }
217
 
218
+ /**
219
+ * Plugin page display.
220
+ */
221
+ public function display_plugin_page() {
222
+ if ( isset( $_GET['action'] ) && 'upload-demo' === $_GET['action'] ) {
223
+ $this->rddi_upload_demo_pack();
224
+ }
225
+ else{ ?>
226
+ <div class="wrap">
227
+ <h1><?php
228
+ esc_html_e( 'RARA Demo Import', 'rara-one-click-demo-import' );
229
+ if ( current_user_can( 'upload_files' ) ) {
230
+ echo ' <button type="button" class="upload-view-toggle page-title-action hide-if-no-js tg-demo-upload" aria-expanded="false">' . __( 'Upload Demo', 'rara-one-click-demo-import' ) . '</button>';
231
+ }
232
+ ?>
233
+ </h1>
234
+ <div id="tabs-container">
235
+ <div class="tab">
236
+ <ul class="tabs-menu">
237
+ <?php
238
+ $settings_tab = $this->rrdi_settings_option_tabs();
239
+ $count = 0;
240
+ foreach ($settings_tab as $key => $value) {
241
+ $tab_label = preg_replace('/_/', ' ', $key);
242
+ ?>
243
+ <li <?php if($count==0){ ?>class="current"<?php } ?>><a href="<?php echo $key;?>"><?php echo $tab_label;?></a></li>
244
+ <?php $count++;
245
+ } ?>
246
+ </ul>
247
+ <?php
248
+ $counter = 0;
249
+ foreach ($settings_tab as $key => $value) { ?>
250
+ <div id="<?php echo $key;?>" class="tab-content" <?php if($counter==0){ ?> style="display: block;" <?php } ?>>
251
+ <?php
252
+ include_once RRDI_PATH . '/includes/settings/'.$value;
253
+ ?>
254
+ </div>
255
+ <?php $counter++; } ?>
256
+ </div>
257
  </div>
258
+ </div>
259
+ <?php
260
+ }
261
+ }
262
 
263
+ private function prepare_demos_for_js( $demos = null ) {
264
+ $prepared_demos = array();
265
+ $current_template = get_option( 'template' );
266
+ $demo_imported_id = get_option( 'rara_demo_imported_id' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
 
268
+ /**
269
+ * Filters demo data before it is prepared for JavaScript.
270
+ *
271
+ * @param array $prepared_demos An associative array of demo data. Default empty array.
272
+ * @param null|array $demos An array of demo config to prepare, if any.
273
+ * @param string $demo_imported_id The current demo imported id.
274
+ */
275
+ $prepared_demos = (array) apply_filters( 'rara_demo_importer_pre_prepare_demos_for_js', array(), $demos, $demo_imported_id );
276
 
277
+ if ( ! empty( $prepared_demos ) ) {
278
+ return $prepared_demos;
279
+ }
280
 
281
+ // Make sure the imported demo is listed first.
282
+ if ( isset( $demos[ $demo_imported_id ] ) ) {
283
+ $prepared_demos[ $demo_imported_id ] = array();
284
+ }
285
 
286
+ if ( ! empty( $demos ) ) {
287
+ foreach ( $demos as $demo_id => $demo_data ) {
288
+ $demo_notices = array();
289
+ $encoded_slug = urlencode( $demo_id );
290
+ $demo_package = isset( $demo_data['demo_pack'] ) ? $demo_data['demo_pack'] : false;
291
+ $plugins_list = isset( $demo_data['plugins_list'] ) ? $demo_data['plugins_list'] : array();
 
292
 
293
+ // Plugins status.
294
+ foreach ( $plugins_list as $plugin => $plugin_data ) {
295
+ $plugins_list[ $plugin ]['is_active'] = is_plugin_active( $plugin_data['slug'] );
 
 
 
 
 
296
  }
297
 
298
+ // Add demo notices.
299
+ if ( isset( $demo_data['template'] ) && $current_template !== $demo_data['template'] ) {
300
+ $demo_notices['required_theme'] = true;
301
+ } elseif ( wp_list_filter( $plugins_list, array( 'required' => true, 'is_active' => false ) ) ) {
302
+ $demo_notices['required_plugins'] = true;
303
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
 
305
+ // Prepare all demos.
306
+ $prepared_demos[ $demo_id ] = array(
307
+ 'id' => $demo_id,
308
+ 'name' => $demo_data['name'],
309
+ 'theme' => $demo_data['theme'],
310
+ 'package' => $demo_package,
311
+ 'screenshot' => $this->import_file_url( $demo_id, 'screenshot.jpg' ),
312
+ 'description' => isset( $demo_data['description'] ) ? $demo_data['description'] : '',
313
+ 'author' => isset( $demo_data['author'] ) ? $demo_data['author'] : __( 'rara', 'rara-one-click-demo-importer' ),
314
+ 'authorAndUri' => '<a href="http://rara.com" target="_blank">rara</a>',
315
+ 'version' => isset( $demo_data['version'] ) ? $demo_data['version'] : '1.1.0',
316
+ 'active' => $demo_id === $demo_imported_id,
317
+ 'hasNotice' => $demo_notices,
318
+ 'plugins' => $plugins_list,
319
+ 'actions' => array(
320
+ 'preview' => home_url( '/' ),
321
+ 'demo_url' => $demo_data['demo_url'],
322
+ 'delete' => current_user_can( 'upload_files' ) ? wp_nonce_url( admin_url( 'themes.php?page=demo-importer&browse=uploads&action=delete&amp;demo_pack=' . urlencode( $demo_id ) ), 'delete-demo_' . $demo_id ) : null,
323
+ ),
324
+ );
325
  }
326
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
327
 
328
+ /**
329
+ * Filters the demos prepared for JavaScript.
330
+ *
331
+ * Could be useful for changing the order, which is by name by default.
332
+ *
333
+ * @param array $prepared_demos Array of demos.
334
+ */
335
+ $prepared_demos = apply_filters( 'rara_demo_importer_prepare_demos_for_js', $prepared_demos );
336
+ $prepared_demos = array_values( $prepared_demos );
337
+ return array_filter( $prepared_demos );
338
  }
 
 
339
  /**
340
  * Enqueue admin scripts (JS and CSS)
341
  *
357
  ),
358
  )
359
  );
 
360
  wp_enqueue_style( 'rrdi-main-css', RRDI_URL . 'assets/css/style.css', array() , RRDI_VERSION );
361
  }
362
  }
includes/settings/installed-demos.php ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="RRDI__intro-notice notice notice-warning is-dismissible">
2
+ <p><?php $msg = __( 'Before you begin, make sure all the required plugins are activated.', 'rara-one-click-demo-import' ); echo apply_filters( 'rrdi_before_import_msg', $msg); ?>
3
+ </p>
4
+ </div>
5
+ <div class="rrdi wrap about-wrap">
6
+
7
+ <h2><?php esc_html_e( 'Rara One Click Demo Import', 'rara-one-click-demo-import' ); ?></h2>
8
+
9
+ <?php
10
+
11
+ // Display warrning if PHP safe mode is enabled, since we wont be able to change the max_execution_time.
12
+ if ( ini_get( 'safe_mode' ) ) {
13
+ printf(
14
+ esc_html__( '%sWarning: your server is using %sPHP safe mode%s. This means that you might experience server timeout errors.%s', 'rara-one-click-demo-import' ),
15
+ '<div class="notice notice-warning is-dismissible"><p>',
16
+ '<strong>',
17
+ '</strong>',
18
+ '</p></div>'
19
+ );
20
+ }
21
+
22
+ // Start output buffer for displaying the plugin intro text.
23
+ ob_start();
24
+ ?>
25
+
26
+ <div class="RRDI__intro-text">
27
+
28
+ <p class="about-description">
29
+ <?php
30
+ $link = '<a href="https://raratheme.com/">Rara Theme</a>';
31
+ $bold = '<b>';
32
+ $boldclose = '</b>';
33
+
34
+ $msg = sprintf( __( 'Upload your theme’s live demo content and settings with a click. If you are using premium themes by %8$s, just click %1$s Import Now %2$s button. Otherwise, download zip files from official website of %3$s and upload it as mentioned in %4$s Welcome %5$s tab and click %6$s Import Now %7$s. As simple as that.', 'rara-one-click-demo-import' ), $bold, $boldclose, $link, $bold, $boldclose, $bold, $boldclose, $link); echo apply_filters( 'rrdi_import_instruction',$msg ); ?>
35
+ </p>
36
+
37
+ <h3><?php esc_html_e( 'The following data will be imported:', 'rara-one-click-demo-import' ); ?></h3>
38
+
39
+ <ul>
40
+ <li><?php esc_html_e( 'Posts', 'rara-one-click-demo-import' ); ?></li>
41
+ <li><?php esc_html_e( 'Pages', 'rara-one-click-demo-import' ); ?></li>
42
+ <li><?php esc_html_e( 'Images', 'rara-one-click-demo-import' ); ?></li>
43
+ <li><?php esc_html_e( 'Widgets', 'rara-one-click-demo-import' ); ?></li>
44
+ <li><?php esc_html_e( 'Menus', 'rara-one-click-demo-import' ); ?></li>
45
+ <li><?php esc_html_e( 'Settings', 'rara-one-click-demo-import' ); ?></li>
46
+ </ul>
47
+ <?php
48
+ $wpreset = '<a href="https://wordpress.org/plugins/wp-reset">WP Reset</a>'; ?>
49
+ <p><b><?php $msg = sprintf( __( 'NOTE: Please import the demo content only on fresh WordPress installation. You can reset your WordPress Installation using any reset plugin like %1$s by WP Dev.','rara-one-click-demo-import' ), $wpreset ); echo apply_filters( 'rrdi_fresh_install_instruction',$msg );?></b></p>
50
+
51
+ <hr>
52
+
53
+ </div>
54
+
55
+ <?php
56
+ $plugin_intro_text = ob_get_clean();
57
+
58
+ // Display the plugin intro text (can be replaced with custom text through the filter below).
59
+ echo wp_kses_post( apply_filters( 'rrdi/plugin_intro_text', $plugin_intro_text ) );
60
+
61
+ // Check the folder contains at least 1 valid demo config.
62
+ $upload_dir = wp_upload_dir();
63
+ $path = $upload_dir['basedir'] . '/rara-demo-pack/';
64
+ $working_dir = getcwd();
65
+ chdir($path); ## chdir to requested dir
66
+ $ret_val = false;
67
+ if ($p = opendir($path) ) {
68
+ while (false !== ($file = readdir($p))) {
69
+ if ($file{0} != '.' && is_dir($file)) {
70
+ $list[] = date('YmdHis', filemtime($path.'/'.$file)).$path.'/'.$file;
71
+ }
72
+ }
73
+ if( isset($list) )
74
+ {
75
+ rsort($list);
76
+ $ret_val = $list[0];
77
+ }
78
+ }
79
+ chdir($working_dir); ## chdir back to script's dir
80
+
81
+ $my_theme = wp_get_theme();
82
+ $td = $my_theme->get( 'TextDomain' );
83
+
84
+ $sr = explode('/', $ret_val);
85
+ $sr = end($sr);
86
+
87
+ if ( empty( $this->import_files ) ) : ?>
88
+
89
+ <div class="RRDI__file-upload-container">
90
+ <?php $bold= '<b>'; $boldclose = '</b>';?>
91
+ <br><h4 style="color:red"><?php echo sprintf( __( 'To import data, go to %1$s Welcome%2$s tab and upload the demo zip file and import demo data as mentioned there.','rara-one-click-demo-import'), $bold, $boldclose).'</h4>'; ?></h4>
92
+ </div>
93
+
94
+ <?php elseif ( 1 < count( $this->import_files ) ) : ?>
95
+
96
+ <div class="RRDI__multi-select-import">
97
+
98
+ <h2><?php esc_html_e( 'Choose which demo you want to import:', 'rara-one-click-demo-import' ); ?></h2>
99
+
100
+ <select id="RRDI__demo-import-files" class="RRDI__demo-import-files">
101
+ <?php foreach ( $this->import_files as $index => $import_file ) : ?>
102
+ <option value="<?php echo esc_attr( $index ); ?>">
103
+ <?php echo esc_html( $import_file['import_file_name'] ); ?>
104
+ </option>
105
+ <?php endforeach; ?>
106
+ </select>
107
+
108
+ <?php
109
+ // Check if at least one preview image is defined, so we can prepare the structure for display.
110
+ $preview_image_is_defined = false;
111
+ foreach ( $this->import_files as $import_file ) {
112
+ if ( isset( $import_file['import_preview_image_url'] ) ) {
113
+ $preview_image_is_defined = true;
114
+ break;
115
+ }
116
+ }
117
+
118
+ if ( $preview_image_is_defined ) :
119
+ ?>
120
+
121
+ <div class="RRDI__demo-import-preview-container">
122
+
123
+ <p><?php esc_html_e( 'Import preview:', 'rara-one-click-demo-import' ); ?></p>
124
+
125
+ <p class="RRDI__demo-import-preview-image-message js-rrdi-preview-image-message"><?php
126
+ if ( ! isset( $this->import_files[0]['import_preview_image_url'] ) ) {
127
+ esc_html_e( 'No preview image defined for this import.', 'rara-one-click-demo-import' );
128
+ }
129
+ // Leave the img tag below and the p tag above available for later changes via JS.
130
+ ?></p>
131
+
132
+ <img id="RRDI__demo-import-preview-image" class="js-rrdi-preview-image" src="<?php echo ! empty( $this->import_files[0]['import_preview_image_url'] ) ? esc_url( $this->import_files[0]['import_preview_image_url'] ) : ''; ?>">
133
+
134
+ </div>
135
+
136
+ <?php endif; ?>
137
+
138
+ </div>
139
+
140
+ <?php endif;
141
+
142
+ if ( strpos($td, 'pro') === false && !empty( $this->import_files ) ) { ?>
143
+
144
+ <div class="RRDI__file-upload-container">
145
+ <?php $bold= '<b>'; $boldclose = '</b>';?>
146
+ <br><h5 style="color:red"><?php echo sprintf( __( 'Note: For free themes, always upload the appropriate demo zip file from %1$s Welcome%2$s tab and import demo data as mentioned there.','rara-one-click-demo-import'), $bold, $boldclose).'</h4>'; ?></h5>
147
+ </div>
148
+ <?php
149
+ }
150
+
151
+
152
+ $upload_dir = wp_upload_dir();
153
+
154
+ $directory = $upload_dir['basedir']."/rara-demo-pack/";
155
+
156
+ //get all files in specified directory
157
+ $files = glob($directory . "*",GLOB_ONLYDIR);
158
+
159
+ //print each file name
160
+ foreach($files as $file)
161
+ {
162
+ //check to see if the file is a folder/directory
163
+ if(is_dir($file))
164
+ {
165
+ $arr[] = basename($file);
166
+ }
167
+ }
168
+
169
+ function is_url_exists($url){
170
+ $ch = curl_init($url);
171
+ curl_setopt($ch, CURLOPT_NOBODY, true);
172
+ curl_exec($ch);
173
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
174
+
175
+ if($code == 200){
176
+ $status = true;
177
+ }else{
178
+ $status = false;
179
+ }
180
+ curl_close($ch);
181
+ return $status;
182
+ }
183
+ $my_theme = wp_get_theme();
184
+
185
+ if ( is_array( $this->import_files ) && ! empty( $this->import_files[0]['import_notice'] ) ) { ?>
186
+ <div class="RRDI__demo-import-notice js-rrdi-demo-import-notice">
187
+ <?php echo wp_kses_post( $this->import_files[0]['import_notice'] ); ?>
188
+ </div>
189
+ <?php
190
+ }
191
+ ?>
192
+
193
+ <p class="RRDI__button-container">
194
+ <button class="RRDI__button button button-hero button-primary js-rrdi-import-data"><?php esc_html_e( 'Import Now', 'rara-one-click-demo-import' ); ?></button>
195
+ <span><?php esc_html_e( 'Click the button to beign the importing process. Please be patient, the process might take a few minutes.', 'rara-one-click-demo-import' ); ?></span>
196
+ </p>
197
+
198
+ <p class="RRDI__ajax-loader js-rrdi-ajax-loader">
199
+ <span class="spinner"></span> <?php esc_html_e( 'Importing now, please wait!', 'rara-one-click-demo-import' ); ?>
200
+ </p>
201
+
202
+ <div class="RRDI__response js-rrdi-ajax-response"></div>
203
+ </div>
includes/settings/welcome.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="upload-theme">
2
+ <p class="install-help"><?php _e( 'If you have a demo pack in a .zip format, you may install it by uploading it here.', 'rara-one-click-demo-import' ); ?></p>
3
+ <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'themes.php?page=rara-demo-import&action=upload-demo' ); ?>">
4
+ <?php wp_nonce_field( 'demo-upload' ); ?>
5
+ <label class="screen-reader-text" for="demozip"><?php _e( 'Demo zip file', 'rara-one-click-demo-import' ); ?></label>
6
+ <input type="file" id="demozip" name="demozip" />
7
+ <?php submit_button( __( 'Install Now', 'rara-one-click-demo-import' ), 'button', 'install-demo-submit', false ); ?>
8
+ </form>
9
+ </div>
10
+ <ol>
11
+ <li><?php
12
+ $wpreset = '<a href="https://wordpress.org/plugins/wp-reset">WP Reset</a>';
13
+ echo sprintf( __( 'Before you begin, make sure you are importing the demo content on fresh WordPress Installation. However, if you want to reset your old WordPress installation, you can use any reset plugin like %1$s.' ), $wpreset );?></li>
14
+ <li>
15
+ <?php
16
+ $link = '<a href="https://raratheme.com/">Rara Theme</a>';
17
+ $demos = '<a href="https://raratheme.com/">Theme Demos</a>';
18
+ $bold = '<b>';
19
+ $boldclose = '</b>';
20
+ echo sprintf( __( 'If you are using premium themes by %1$s, just go to %2$s Import Demo %3$s and click %4$s Import Now %5$s.', 'rara-one-click-demo-import' ), $link, $bold, $boldclose, $bold, $boldclose ); ?>
21
+ </li>
22
+ <li><?php echo sprintf( __( 'If you are using free themes by %1$s, go to %2$s and download demo zip file.','rara-one-click-demo-import'), $link, $demos );?></li>
23
+ <li><?php echo sprintf( __( 'Click %1$s Upload Demo %2$s button on the top of this Page.','rara-one-click-demo-import'), $bold, $boldclose );?></li>
24
+ <li><?php echo sprintf( __( 'Browse the downloaded demo zip file and click %1$s Install Now %2$s.','rara-one-click-demo-import' ), $bold, $boldclose );?></li>
25
+ <li><?php echo sprintf( __( 'After successful installation, return to %1$s Demo Importer %2$s and go to %1$s Import Demo %2$s.','rara-one-click-demo-import'),$bold, $boldclose );?></li>
26
+ <li><?php echo sprintf( __( 'Click %1$s Import Now %2$s and wait for few minutes. Done!','rara-one-click-demo-import' ),$bold, $boldclose );?></li>
27
+ </ol>
includes/vendor/class-demo-installer-skin.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Upgrader API: Plugin_Upgrader_Skin class
4
+ *
5
+ * Demo Installer Skin for the WordPress Demo Importer.
6
+ *
7
+ * @class RDDI_Demo_Installer_Skin
8
+ * @extends WP_Upgrader_Skin
9
+ * @version 1.0.0
10
+ * @package Importer/Classes
11
+ * @category Admin
12
+ * @author ThemeGrill
13
+ */
14
+
15
+ if ( ! defined( 'ABSPATH' ) ) {
16
+ exit;
17
+ }
18
+
19
+ /**
20
+ * RDDI_Demo_Installer_Skin Class.
21
+ */
22
+ class RDDI_Demo_Installer_Skin extends WP_Upgrader_Skin {
23
+ public $type;
24
+
25
+ /**
26
+ *
27
+ * @param array $args
28
+ */
29
+ public function __construct( $args = array() ) {
30
+ $defaults = array( 'type' => 'web', 'url' => '', 'demo' => '', 'nonce' => '', 'title' => '' );
31
+ $args = wp_parse_args( $args, $defaults );
32
+
33
+ $this->type = $args['type'];
34
+
35
+ parent::__construct( $args );
36
+ }
37
+
38
+ /**
39
+ * @access public
40
+ */
41
+ public function after() {
42
+ $install_actions = array();
43
+
44
+ $from = isset( $_GET['from'] ) ? wp_unslash( $_GET['from'] ) : 'demos';
45
+
46
+ if ( 'web' == $this->type ) {
47
+ $install_actions['demos_page'] = '<a href="' . admin_url( 'themes.php?page=rara-demo-import&browse=uploads' ) . '" target="_parent">' . __( 'Return to Demo Importer', 'rara-one-click-demo-import' ) . '</a>';
48
+ } elseif ( 'upload' == $this->type && 'demos' == $from ) {
49
+ $install_actions['demos_page'] = '<a href="' . admin_url( 'themes.php?page=rara-demo-import&browse=uploads' ) . '">' . __( 'Return to Demo Importer', 'rara-one-click-demo-import' ) . '</a>';
50
+ } else {
51
+ $install_actions['demos_page'] = '<a href="' . admin_url( 'themes.php?page=rara-demo-import&browse=uploads' ) . '" target="_parent">' . __( 'Return to Demos page', 'rara-one-click-demo-import' ) . '</a>';
52
+ }
53
+
54
+ /**
55
+ * Filters the list of action links available following a single demo installation.
56
+ * @param array $install_actions Array of demo action links.
57
+ */
58
+ $install_actions = apply_filters( 'themegrill_demo_install_complete_actions', $install_actions );
59
+
60
+ if ( ! empty( $install_actions ) ) {
61
+ $this->feedback( implode( ' | ', (array) $install_actions ) );
62
+ }
63
+ }
64
+ }
includes/vendor/class-demo-upgrader.php ADDED
@@ -0,0 +1,354 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Upgrade API: RDDI_Demo_Upgrader class
4
+ *
5
+ * Core class used for upgrading/installing demos.
6
+ *
7
+ * It is designed to upgrade/install demo from a local zip, remote zip URL,
8
+ * or uploaded zip file.
9
+ *
10
+ * @see WP_Upgrader
11
+ */
12
+ class RDDI_Demo_Upgrader extends WP_Upgrader {
13
+
14
+ /**
15
+ * Result of the demo upgrade offer.
16
+ *
17
+ * @since 2.8.0
18
+ * @access public
19
+ * @var array|WP_Error $result
20
+ * @see WP_Upgrader::$result
21
+ */
22
+ public $result;
23
+
24
+ /**
25
+ * Whether multiple demos are being upgraded/installed in bulk.
26
+ *
27
+ * @since 2.9.0
28
+ * @access public
29
+ * @var bool $bulk
30
+ */
31
+ public $bulk = false;
32
+
33
+ /**
34
+ * Initialize the install strings.
35
+ *
36
+ * @since 2.8.0
37
+ * @access public
38
+ */
39
+ public function install_strings() {
40
+ $this->strings['no_package'] = __( 'Install package not available.', 'rara-one-click-demo-importer' );
41
+ $this->strings['downloading_package'] = __( 'Downloading install package from <span class="code">%s</span>&#8230;', 'rara-one-click-demo-importer' );
42
+ $this->strings['unpack_package'] = __( 'Unpacking the package&#8230;', 'rara-one-click-demo-importer' );
43
+ $this->strings['remove_old'] = __( 'Removing the old version of the demo&#8230;', 'rara-one-click-demo-importer' );
44
+ $this->strings['remove_old_failed'] = __( 'Could not remove the old demo.', 'rara-one-click-demo-importer' );
45
+ $this->strings['installing_package'] = __( 'Installing the demo&#8230;', 'rara-one-click-demo-importer' );
46
+ $this->strings['no_files'] = __( 'The demo contains no files.', 'rara-one-click-demo-importer' );
47
+ $this->strings['process_failed'] = __( 'Demo install failed.', 'rara-one-click-demo-importer' );
48
+ $bold = '<b>';
49
+ $boldclose = '</b>';
50
+ $this->strings['process_success'] = __( 'Demo installed successfully.' , 'rara-one-click-demo-importer' ).'<br><br><span style="color: green">'.sprintf( __( 'Now, return to the %1$s Demo Importer %2$s page by clicking below link and go to %3$s Import Demo %4$s tab and click %5$s Import Now %6$s button.','rara-one-click-demo-importer'), $bold, $boldclose, $bold, $boldclose, $bold, $boldclose ).'</span>';
51
+ }
52
+
53
+ /**
54
+ * Install a demo package.
55
+ *
56
+ * @since 2.8.0
57
+ * @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
58
+ * @access public
59
+ *
60
+ * @param string $package The full local path or URI of the package.
61
+ * @param array $args {
62
+ * Optional. Other arguments for installing a demo package. Default empty array.
63
+ *
64
+ * @type bool $clear_update_cache Whether to clear the updates cache if successful.
65
+ * Default true.
66
+ * }
67
+ *
68
+ * @return bool|WP_Error True if the install was successful, false or a WP_Error object otherwise.
69
+ */
70
+ public function install( $package, $args = array() ) {
71
+ $upload_dir = wp_upload_dir();
72
+
73
+ $defaults = array(
74
+ 'clear_update_cache' => true,
75
+ );
76
+ $parsed_args = wp_parse_args( $args, $defaults );
77
+
78
+ $this->init();
79
+ $this->install_strings();
80
+
81
+ add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
82
+
83
+ $this->run( array(
84
+ 'package' => $package,
85
+ 'destination' => $upload_dir['basedir'] . '/rara-demo-pack',
86
+ 'clear_destination' => true, // Do overwrite files.
87
+ 'protect_destination' => true,
88
+ 'clear_working' => true,
89
+ 'hook_extra' => array(
90
+ 'type' => 'demo',
91
+ 'action' => 'install',
92
+ ),
93
+ ) );
94
+
95
+ remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
96
+
97
+ if ( ! $this->result || is_wp_error( $this->result ) ) {
98
+ return $this->result;
99
+ }
100
+
101
+ return true;
102
+ }
103
+
104
+ /**
105
+ * Check that the package source contains a valid demo.
106
+ *
107
+ * Hooked to the {@see 'upgrader_source_selection'} filter by RDDI_Demo_Upgrader::install().
108
+ * It will return an error if the demo doesn't have rara-demo-config.php
109
+ * files.
110
+ *
111
+ * @since 3.3.0
112
+ * @access public
113
+ *
114
+ * @global WP_Filesystem_Base $wp_filesystem Subclass
115
+ * @global array $wp_theme_directories
116
+ *
117
+ * @param string $source The full path to the package source.
118
+ * @return string|WP_Error The source or a WP_Error.
119
+ */
120
+ public function check_package( $source ) {
121
+ global $wp_filesystem, $wp_theme_directories;
122
+
123
+
124
+ if ( is_wp_error( $source ) )
125
+ return $source;
126
+ // Check the folder contains a valid demo.
127
+ $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
128
+
129
+ if ( ! is_dir( $working_directory ) ) // Sanity check, if the above fails, let's not prevent installation.
130
+ return $source;
131
+
132
+ // A proper archive should have a rara-demo-config.php file in the single subdirectory
133
+ if ( ! file_exists( $working_directory . 'import-hooks.php' ) ) {
134
+ return new WP_Error( 'incompatible_archive_no_demos', $this->strings['incompatible_archive'], __( 'No valid demos were found.', 'rara-one-click-demo-importer' ) );
135
+ }
136
+
137
+ return $source;
138
+ }
139
+
140
+ /**
141
+ * Install a package.
142
+ *
143
+ * Copies the contents of a package form a source directory, and installs them in
144
+ * a destination directory. Optionally removes the source. It can also optionally
145
+ * clear out the destination folder if it already exists.
146
+ *
147
+ * Stuck with this until a fix for https://core.trac.wordpress.org/ticket/38946.
148
+ * We use a custom upgrader, just like WordPress does.
149
+ *
150
+ * @since 2.8.0
151
+ * @access public
152
+ *
153
+ * @global WP_Filesystem_Base $wp_filesystem Subclass
154
+ * @global array $wp_theme_directories
155
+ *
156
+ * @param array|string $args {
157
+ * Optional. Array or string of arguments for installing a package. Default empty array.
158
+ *
159
+ * @type string $source Required path to the package source. Default empty.
160
+ * @type string $destination Required path to a folder to install the package in.
161
+ * Default empty.
162
+ * @type bool $clear_destination Whether to delete any files already in the destination
163
+ * folder. Default false.
164
+ * @type bool $clear_working Whether to delete the files from the working directory
165
+ * after copying to the destination. Default false.
166
+ * @type bool $protect_destination Whether to protect against deleting any files already
167
+ * in the destination folder. Default false.
168
+ * @type bool $abort_if_destination_exists Whether to abort the installation if
169
+ * the destination folder already exists. Default true.
170
+ * @type array $hook_extra Extra arguments to pass to the filter hooks called by
171
+ * WP_Upgrader::install_package(). Default empty array.
172
+ * }
173
+ *
174
+ * @return array|WP_Error The result (also stored in `WP_Upgrader::$result`), or a WP_Error on failure.
175
+ */
176
+ public function install_package( $args = array() ) {
177
+ global $wp_filesystem, $wp_theme_directories;
178
+
179
+ $defaults = array(
180
+ 'source' => '', // Please always pass this
181
+ 'destination' => '', // and this
182
+ 'clear_destination' => false,
183
+ 'clear_working' => false,
184
+ 'protect_destination' => true, // If fixed in core then it will be false :)
185
+ 'abort_if_destination_exists' => true,
186
+ 'hook_extra' => array(),
187
+ );
188
+
189
+ $args = wp_parse_args( $args, $defaults );
190
+
191
+ // These were previously extract()'d.
192
+ $source = $args['source'];
193
+ $destination = $args['destination'];
194
+ $clear_destination = $args['clear_destination'];
195
+
196
+ @set_time_limit( 300 );
197
+
198
+ if ( empty( $source ) || empty( $destination ) ) {
199
+ return new WP_Error( 'bad_request', $this->strings['bad_request'] );
200
+ }
201
+ $this->skin->feedback( 'installing_package' );
202
+
203
+ /**
204
+ * Filters the install response before the installation has started.
205
+ *
206
+ * Returning a truthy value, or one that could be evaluated as a WP_Error
207
+ * will effectively short-circuit the installation, returning that value
208
+ * instead.
209
+ *
210
+ * @since 2.8.0
211
+ *
212
+ * @param bool|WP_Error $response Response.
213
+ * @param array $hook_extra Extra arguments passed to hooked filters.
214
+ */
215
+ $res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );
216
+
217
+ if ( is_wp_error( $res ) ) {
218
+ return $res;
219
+ }
220
+
221
+ // Retain the Original source and destinations
222
+ $remote_source = $args['source'];
223
+ $local_destination = $destination;
224
+
225
+ $source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) );
226
+ $remote_destination = $wp_filesystem->find_folder( $local_destination );
227
+
228
+ // Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
229
+ if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { // Only one folder? Then we want its contents.
230
+ $source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
231
+ } elseif ( count( $source_files ) == 0 ) {
232
+ return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
233
+ } else { // It's only a single file, the upgrader will use the folder name of this file as the destination folder. Folder name is based on zip filename.
234
+ $source = trailingslashit( $args['source'] );
235
+ }
236
+
237
+ /**
238
+ * Filters the source file location for the upgrade package.
239
+ *
240
+ * @since 2.8.0
241
+ * @since 4.4.0 The $hook_extra parameter became available.
242
+ *
243
+ * @param string $source File source location.
244
+ * @param string $remote_source Remote file source location.
245
+ * @param WP_Upgrader $this WP_Upgrader instance.
246
+ * @param array $hook_extra Extra arguments passed to hooked filters.
247
+ */
248
+ $source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this, $args['hook_extra'] );
249
+
250
+ if ( is_wp_error( $source ) ) {
251
+ return $source;
252
+ }
253
+
254
+ // Has the source location changed? If so, we need a new source_files list.
255
+ if ( $source !== $remote_source ) {
256
+ $source_files = array_keys( $wp_filesystem->dirlist( $source ) );
257
+ }
258
+
259
+ /*
260
+ * Protection against deleting files in any important base directories.
261
+ * Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the
262
+ * destination directory (WP_PLUGIN_DIR / wp-content/themes) intending
263
+ * to copy the directory into the directory, whilst they pass the source
264
+ * as the actual files to copy.
265
+ */
266
+ $protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' );
267
+
268
+ if ( is_array( $wp_theme_directories ) ) {
269
+ $protected_directories = array_merge( $protected_directories, $wp_theme_directories );
270
+ }
271
+
272
+ if ( in_array( $destination, $protected_directories ) || $args['protect_destination'] ) {
273
+ $remote_destination = trailingslashit( $remote_destination ) . trailingslashit( basename( $source ) );
274
+ $destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) );
275
+ }
276
+
277
+ if ( $clear_destination ) {
278
+ // We're going to clear the destination if there's something there.
279
+ $this->skin->feedback( 'remove_old' );
280
+
281
+ $removed = $this->clear_destination( $remote_destination );
282
+
283
+ /**
284
+ * Filters whether the upgrader cleared the destination.
285
+ *
286
+ * @since 2.8.0
287
+ *
288
+ * @param mixed $removed Whether the destination was cleared. true on success, WP_Error on failure
289
+ * @param string $local_destination The local package destination.
290
+ * @param string $remote_destination The remote package destination.
291
+ * @param array $hook_extra Extra arguments passed to hooked filters.
292
+ */
293
+ $removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] );
294
+
295
+ if ( is_wp_error( $removed ) ) {
296
+ return $removed;
297
+ }
298
+ } elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists( $remote_destination ) ) {
299
+ // If we're not clearing the destination folder and something exists there already, Bail.
300
+ // But first check to see if there are actually any files in the folder.
301
+ $_files = $wp_filesystem->dirlist( $remote_destination );
302
+ if ( ! empty( $_files ) ) {
303
+ $wp_filesystem->delete( $remote_source, true ); // Clear out the source files.
304
+ return new WP_Error( 'folder_exists', $this->strings['folder_exists'], $remote_destination );
305
+ }
306
+ }
307
+
308
+ // Create destination if needed
309
+ if ( ! $wp_filesystem->exists( $remote_destination ) ) {
310
+ if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
311
+ return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
312
+ }
313
+ }
314
+ // Copy new version of item into place.
315
+ $result = copy_dir( $source, $remote_destination );
316
+ if ( is_wp_error( $result ) ) {
317
+ if ( $args['clear_working'] ) {
318
+ $wp_filesystem->delete( $remote_source, true );
319
+ }
320
+ return $result;
321
+ }
322
+
323
+ // Clear the Working folder?
324
+ if ( $args['clear_working'] ) {
325
+ $wp_filesystem->delete( $remote_source, true );
326
+ }
327
+
328
+ $destination_name = basename( str_replace( $local_destination, '', $destination ) );
329
+ if ( '.' == $destination_name ) {
330
+ $destination_name = '';
331
+ }
332
+
333
+ $this->result = compact( 'source', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination' );
334
+
335
+ /**
336
+ * Filters the install response after the installation has finished.
337
+ *
338
+ * @since 2.8.0
339
+ *
340
+ * @param bool $response Install response.
341
+ * @param array $hook_extra Extra arguments passed to hooked filters.
342
+ * @param array $result Installation result data.
343
+ */
344
+ $res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result );
345
+
346
+ if ( is_wp_error( $res ) ) {
347
+ $this->result = $res;
348
+ return $res;
349
+ }
350
+
351
+ // Bombard the calling function will all the info which we've just used.
352
+ return $this->result;
353
+ }
354
+ }
includes/vendor/class-rrdi-customizer-importer.php CHANGED
@@ -38,7 +38,6 @@ class RRDI_Customizer_Importer {
38
  )
39
  );
40
  }
41
-
42
  // Get the upload data.
43
  $raw = RRDI_Helpers::data_from_file( $import_file_path );
44
 
38
  )
39
  );
40
  }
 
41
  // Get the upload data.
42
  $raw = RRDI_Helpers::data_from_file( $import_file_path );
43
 
rara-demo-import.php → rara-one-click-demo-import.php RENAMED
@@ -3,7 +3,7 @@
3
  Plugin Name: RARA One Click Demo Import
4
  Plugin URI: https://wordpress.org/plugins/rara-one-click-demo-import/
5
  Description: Import demo content, widgets and settings of themes made by RaraTheme.com with just one click.
6
- Version: 1.0.2
7
  Author: raratheme
8
  Author URI: https://www.raratheme.com
9
  License: GPL3
@@ -17,9 +17,10 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
17
  define( 'RRDI_PATH', plugin_dir_path( __FILE__ ) );
18
 
19
  // Current version of the plugin.
20
- define( 'RRDI_VERSION', '1.0.1' );
21
 
22
  // Path/URL to root of this plugin, with trailing slash.
23
  define( 'RRDI_URL', plugin_dir_url( __FILE__ ) );
24
 
25
- require RRDI_PATH . 'includes/class-rrdi-init.php';
 
3
  Plugin Name: RARA One Click Demo Import
4
  Plugin URI: https://wordpress.org/plugins/rara-one-click-demo-import/
5
  Description: Import demo content, widgets and settings of themes made by RaraTheme.com with just one click.
6
+ Version: 1.0.5
7
  Author: raratheme
8
  Author URI: https://www.raratheme.com
9
  License: GPL3
17
  define( 'RRDI_PATH', plugin_dir_path( __FILE__ ) );
18
 
19
  // Current version of the plugin.
20
+ define( 'RRDI_VERSION', '1.0.5' );
21
 
22
  // Path/URL to root of this plugin, with trailing slash.
23
  define( 'RRDI_URL', plugin_dir_url( __FILE__ ) );
24
 
25
+ require RRDI_PATH . 'includes/class-rrdi-init.php';
26
+
readme.txt CHANGED
@@ -1,47 +1,51 @@
1
- === RARA One Click Demo Import ===
2
  Contributors: raratheme
3
- Donate link: https://raratheme.com/
4
  Tags: import, content, demo, data, widgets, settings
5
  Requires at least: 4.0.0
6
- Tested up to: 4.7.3
7
- Stable tag: 1.0.2
8
  License: GPLv3 or later
9
 
10
- Import demo content, widgets and settings of themes made by RaraTheme.com with just one click.
11
 
12
  == Description ==
13
 
14
- You just downloaded, installed and activated a great looking WordPress theme. But, hey! The website doesn't look anything like the theme's live demo.
15
 
16
- It is because you don't have the settings and the contents like the demo.
17
 
18
- This plugin will help you import the demo content, including settings of the widgets and the customizer, with a click.
19
 
20
  The demo content will make your website look like the preview of a theme so that you get a basic guideline for making your website.
21
 
22
  Once installed and activated, Rara One Click Demo Import will be accessible through **Appearance > Rara Demo Import**.
23
 
24
- If you use our free theme, you need to upload three types of files to import the demo. You can find them on our website.
25
 
26
- 1. XML File: This file contains the actual demo contents. This file is required for demo import.
27
-
28
- 2. WIE or JSON File: This is optional file. This file imports widgets. You can create the WIE or JSON File using [Widget Importer & Exporter](https://wordpress.org/plugins/widget-importer-exporter/) plugin.
29
-
30
- 3. DAT File: This is also optional file. This file will import customizer settings. You can create a DAT file using [Customizer Export/Import] (https://wordpress.org/plugins/customizer-export-import/) plugin.
31
 
32
  You can find the detail documentation [here](https://raratheme.com/blog/import-demo-content-rara-themes/)
33
 
 
 
34
  This plugin is based on the 'Theme Demo Import' plugin by Themely, https://wordpress.org/plugins/theme-demo-import/
35
 
36
  As well as the improved WP Import 2.0 plugin by @humanmade, https://github.com/humanmade/WordPress-Importer.
37
 
38
  == Installation ==
 
39
 
40
- **From your WordPress dashboard**
 
 
 
41
 
42
- 1. Visit 'Plugins > Add New',
43
- 2. Search for 'Rara One Click Demo Import' and install the plugin.
44
- 3. Activate 'Rara One Click Demo Import' from your Plugins page.
 
 
 
45
 
46
  Once the plugin is activated, you will find the actual import page in **Appearance > Rara Demo Import**
47
 
@@ -59,22 +63,19 @@ The log file will be registered in the *wp-admin -> Media* section.
59
 
60
  = I can't activate the plugin because of a fatal error. What can I do? =
61
 
62
- *Update: There is a admin error notice, stating that the minimal PHP version required for this plugin is 5.3.2.*
63
 
64
  You want to activate the plugin, but this error shows up:
65
 
66
  *Plugin could not be activated because it triggered a fatal error*
67
 
68
- This happens, because your hosting server is using a very old version of PHP. This plugin requires PHP version of at least **5.3.x**, but we recommend version *5.6.x*. Please contact your hosting company and ask them to update the PHP version for your site.
69
-
70
- =I am a theme developer. How do I use the plugin on my themes?=
71
-
72
- If you are a theme developer, you can find detailed documentation [here](https://raratheme.com/blog/rara-one-click-demo-import-plugin-developers/)
73
 
74
  == Screenshots ==
75
 
76
- 1. No pre-defined import files
77
- 2. Pre-defined import files
 
78
 
79
  == License ==
80
 
@@ -109,7 +110,6 @@ You should have received a copy of the GNU General Public License along
109
  with this program; if not, write to the Free Software Foundation, Inc.,
110
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
111
 
112
-
113
  == Changelog ==
114
 
115
  = 1.0.0 =
@@ -120,4 +120,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
120
  * FILTERS ADDED
121
 
122
  = 1.0.2 =
123
- *CODE CLEANUP
 
 
 
 
 
 
 
 
 
 
1
+ === Rara One Click Demo Import ===
2
  Contributors: raratheme
 
3
  Tags: import, content, demo, data, widgets, settings
4
  Requires at least: 4.0.0
5
+ Tested up to: 4.8.1
6
+ Stable tag: 1.0.5
7
  License: GPLv3 or later
8
 
9
+ Make your website look like the live demo of the theme with a click!
10
 
11
  == Description ==
12
 
13
+ Do you love the demos of the themes made by Rara Theme? Or, need a guideline for setting up the themes?
14
 
15
+ Then, all you need is this plugin!
16
 
17
+ Rara One Click Demo Import plugin will help you import the demo content, including settings of the widgets and the customizer, with a click.
18
 
19
  The demo content will make your website look like the preview of a theme so that you get a basic guideline for making your website.
20
 
21
  Once installed and activated, Rara One Click Demo Import will be accessible through **Appearance > Rara Demo Import**.
22
 
23
+ If you use Premium themes made by Rara Themes, just click on ‘Import Now’ button and your website will look like the demo of the activated theme in no time.
24
 
25
+ If you use free themes made, download the demo files from [Rara Theme](https://raratheme.com), upload it using ‘Upload Demo’ button on this plugin, and click Import Now. As simple as that.
 
 
 
 
26
 
27
  You can find the detail documentation [here](https://raratheme.com/blog/import-demo-content-rara-themes/)
28
 
29
+ If you need help, contact our support team [here](https://raratheme.com/support-ticket/).
30
+
31
  This plugin is based on the 'Theme Demo Import' plugin by Themely, https://wordpress.org/plugins/theme-demo-import/
32
 
33
  As well as the improved WP Import 2.0 plugin by @humanmade, https://github.com/humanmade/WordPress-Importer.
34
 
35
  == Installation ==
36
+ **Method 1:**
37
 
38
+ On your WordPress admin dashboard
39
+ Visit ‘Plugins > Add New’
40
+ Search for ‘RARA One Click Demo Import’ and install the plugin.
41
+ Activate ‘RARA One Click Demo Import ’ from your Plugins page.
42
 
43
+ **Method 2:**
44
+
45
+ Download the plugin from WordPress.org repository
46
+ On your WordPress admin dashboard, go to ‘Plugins> Add New> Upload Plugin’.
47
+ Upload the downloaded plugin file (rara-one-click-demo-import.zip) and click ‘Install Now’
48
+ Activate ‘Rara One Click Demo Import’ from your Plugins page.
49
 
50
  Once the plugin is activated, you will find the actual import page in **Appearance > Rara Demo Import**
51
 
63
 
64
  = I can't activate the plugin because of a fatal error. What can I do? =
65
 
66
+ *Update: There is an admin error notice, stating that the minimal PHP version required for this plugin is 5.3.2.*
67
 
68
  You want to activate the plugin, but this error shows up:
69
 
70
  *Plugin could not be activated because it triggered a fatal error*
71
 
72
+ This happens because your hosting server is using a very old version of PHP. This plugin requires PHP version of at least **5.3.x**, but we recommend version *5.6.x*. Please contact your hosting company and ask them to update the PHP version for your site.
 
 
 
 
73
 
74
  == Screenshots ==
75
 
76
+ 1. Upload Demo Button
77
+ 2. Upload Demo Screen
78
+ 3. Import Now
79
 
80
  == License ==
81
 
110
  with this program; if not, write to the Free Software Foundation, Inc.,
111
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
112
 
 
113
  == Changelog ==
114
 
115
  = 1.0.0 =
120
  * FILTERS ADDED
121
 
122
  = 1.0.2 =
123
+ * CODE CLEANUP
124
+
125
+ = 1.0.3 =
126
+ * PLUGIN DEPENDENCY CHECK
127
+ * COMPATIBILITY TEST
128
+
129
+ = 1.0.4 =
130
+ * COMPATIBILITY TEST
131
+
132
+ = 1.0.5 =
133
+ * RARA THEME DEPENDENT