balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

plugin-page.php (15244B)


      1 <?php
      2 
      3 /**
      4  * The plugin page view - the "settings" page of the plugin.
      5  *
      6  * @package ocdi
      7  */
      8 
      9 namespace OCDI;
     10 
     11 $predefined_themes = $this->import_files;
     12 
     13 
     14 function envato_demo_theme_license_let_to_num( $size ) {
     15 	$l    = substr( $size, -1 );
     16 	$ret  = substr( $size, 0, -1 );
     17 	$byte = 1024;
     18 
     19 	switch ( strtoupper( $l ) ) {
     20 		case 'P':
     21 			$ret *= 1024;
     22 			// No break.
     23 		case 'T':
     24 			$ret *= 1024;
     25 			// No break.
     26 		case 'G':
     27 			$ret *= 1024;
     28 			// No break.
     29 		case 'M':
     30 			$ret *= 1024;
     31 			// No break.
     32 		case 'K':
     33 			$ret *= 1024;
     34 			// No break.
     35 	}
     36 	return $ret;
     37 }
     38 
     39 function get_demo_environment_info() {
     40 	global $wpdb;
     41 
     42 	class plugin_list {
     43 
     44 		use \pluginlist;
     45 	}
     46 	$plugin_list    = new plugin_list();
     47 	$dashboard_slug = $plugin_list->dashboard_slug;
     48 
     49 	// Figure out cURL version, if installed.
     50 	$curl_version = '';
     51 	if ( function_exists( 'curl_version' ) ) {
     52 		$curl_version = curl_version();
     53 		$curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
     54 	}
     55 
     56 	// WP memory limit.
     57 	$wp_memory_limit = envato_demo_theme_license_let_to_num( WP_MEMORY_LIMIT );
     58 	if ( function_exists( 'memory_get_usage' ) ) {
     59 		$wp_memory_limit = max( $wp_memory_limit, envato_demo_theme_license_let_to_num( @ini_get( 'memory_limit' ) ) );
     60 	}
     61 
     62 	// Test POST requests.
     63 	$post_response            = wp_safe_remote_post(
     64 		'https://www.paypal.com/cgi-bin/webscr',
     65 		array(
     66 			'timeout'     => 10,
     67 			'user-agent'  => $dashboard_slug . '/' . wp_get_theme()->version,
     68 			'httpversion' => '1.1',
     69 			'body'        => array(
     70 				'cmd' => '_notify-validate',
     71 			),
     72 		)
     73 	);
     74 	$post_response_successful = false;
     75 	if ( ! is_wp_error( $post_response ) && $post_response['response']['code'] >= 200 && $post_response['response']['code'] < 300 ) {
     76 		$post_response_successful = true;
     77 	}
     78 
     79 	// Test GET requests.
     80 	$get_response            = wp_safe_remote_get( 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . ( is_multisite() ? '1' : '0' ) );
     81 	$get_response_successful = false;
     82 	if ( ! is_wp_error( $post_response ) && $post_response['response']['code'] >= 200 && $post_response['response']['code'] < 300 ) {
     83 		$get_response_successful = true;
     84 	}
     85 
     86 	// Return all environment info. Described by JSON Schema.
     87 	return array(
     88 		'home_url'                  => home_url(),
     89 		'site_url'                  => get_option( 'siteurl' ),
     90 		'version'                   => wp_get_theme()->version,
     91 
     92 		'wp_version'                => get_bloginfo( 'version' ),
     93 		'wp_multisite'              => is_multisite(),
     94 		'wp_memory_limit'           => $wp_memory_limit,
     95 		'wp_debug_mode'             => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
     96 		'wp_cron'                   => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
     97 		'language'                  => get_locale(),
     98 		'external_object_cache'     => wp_using_ext_object_cache(),
     99 		'php_version'               => phpversion(),
    100 		'php_post_max_size'         => envato_demo_theme_license_let_to_num( ini_get( 'post_max_size' ) ),
    101 		'php_max_execution_time'    => ini_get( 'max_execution_time' ),
    102 		'php_max_input_vars'        => ini_get( 'max_input_vars' ),
    103 		'curl_version'              => $curl_version,
    104 		'suhosin_installed'         => extension_loaded( 'suhosin' ),
    105 		'max_upload_size'           => wp_max_upload_size(),
    106 		'default_timezone'          => date_default_timezone_get(),
    107 		'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ),
    108 		'soapclient_enabled'        => class_exists( 'SoapClient' ),
    109 		'domdocument_enabled'       => class_exists( 'DOMDocument' ),
    110 		'gzip_enabled'              => is_callable( 'gzopen' ),
    111 		'mbstring_enabled'          => extension_loaded( 'mbstring' ),
    112 		'remote_post_successful'    => $post_response_successful,
    113 		'remote_post_response'      => ( is_wp_error( $post_response ) ? $post_response->get_error_message() : $post_response['response']['code'] ),
    114 		'remote_get_successful'     => $get_response_successful,
    115 		'remote_get_response'       => ( is_wp_error( $get_response ) ? $get_response->get_error_message() : $get_response['response']['code'] ),
    116 	);
    117 }
    118 
    119 
    120 if ( ! empty( $this->import_files ) && isset( $_GET['import-mode'] ) && 'manual' === $_GET['import-mode'] ) {
    121 	$predefined_themes = array();
    122 }
    123 
    124 ?>
    125 <?php do_action( 'add_tab_menu_for_dashboard', 'demo' ); ?>
    126 <div class="ocdi  wrap  about-wrap">
    127 
    128 	<?php ob_start(); ?>
    129 	<h1 class="ocdi__title  dashicons-before  dashicons-upload"><?php esc_html_e( 'One Click Demo Import', 'pt-ocdi' ); ?></h1>
    130 	<?php
    131 	$plugin_title = ob_get_clean();
    132 
    133 	// Display the plugin title (can be replaced with custom title text through the filter below).
    134 	echo wp_kses_post( apply_filters( 'pt-ocdi/plugin_page_title', $plugin_title ) );
    135 
    136 	// Display warrning if PHP safe mode is enabled, since we wont be able to change the max_execution_time.
    137 	if ( ini_get( 'safe_mode' ) ) {
    138 		printf(
    139 			esc_html__( '%1$sWarning: your server is using %2$sPHP safe mode%3$s. This means that you might experience server timeout errors.%4$s', 'pt-ocdi' ),
    140 			'<div class="notice  notice-warning  is-dismissible"><p>',
    141 			'<strong>',
    142 			'</strong>',
    143 			'</p></div>'
    144 		);
    145 	}
    146 
    147 	// Start output buffer for displaying the plugin intro text.
    148 	ob_start();
    149 	?>
    150 
    151 	<div class="ocdi__intro-notice  notice  notice-warning  is-dismissible">
    152 		<p><?php esc_html_e( 'Before you begin, make sure all the required plugins are activated.', 'pt-ocdi' ); ?></p>
    153 	</div>
    154 
    155 	<div class="ocdi__intro-text">
    156 		<p class="about-description">
    157 			<?php esc_html_e( 'Importing demo data (post, pages, images, theme settings, ...) is the easiest way to setup your theme.', 'pt-ocdi' ); ?>
    158 			<?php esc_html_e( 'It will allow you to quickly edit everything instead of creating content from scratch.', 'pt-ocdi' ); ?>
    159 		</p>
    160 
    161 		<hr>
    162 
    163 		<p><?php esc_html_e( 'When you import the data, the following things might happen:', 'pt-ocdi' ); ?></p>
    164 
    165 		<ul>
    166 			<li><?php esc_html_e( 'No existing posts, pages, categories, images, custom post types or any other data will be deleted or modified.', 'pt-ocdi' ); ?></li>
    167 			<li><?php esc_html_e( 'Posts, pages, images, widgets, menus and other theme settings will get imported.', 'pt-ocdi' ); ?></li>
    168 			<li><?php esc_html_e( 'Please click on the Import button only once and wait, it can take a couple of minutes.', 'pt-ocdi' ); ?></li>
    169 		</ul>
    170 
    171 
    172 
    173 		<hr>
    174 	</div>
    175 
    176 	<?php
    177 	$plugin_intro_text = ob_get_clean();
    178 
    179 	// Display the plugin intro text (can be replaced with custom text through the filter below).
    180 	echo wp_kses_post( apply_filters( 'pt-ocdi/plugin_intro_text', $plugin_intro_text ) );
    181 	?>
    182 
    183 	<?php if ( empty( $this->import_files ) ) : ?>
    184 		<div class="notice  notice-info  is-dismissible">
    185 			<p><?php esc_html_e( 'There are no predefined import files available in this theme. Please upload the import files manually!', 'pt-ocdi' ); ?></p>
    186 		</div>
    187 	<?php endif; ?>
    188 
    189 	<?php if ( empty( $predefined_themes ) ) : ?>
    190 
    191 		<div class="ocdi__file-upload-container">
    192 			<h2><?php esc_html_e( 'Manual demo files upload', 'pt-ocdi' ); ?></h2>
    193 
    194 			<div class="ocdi__file-upload">
    195 				<h3><label for="content-file-upload"><?php esc_html_e( 'Choose a XML file for content import:', 'pt-ocdi' ); ?></label></h3>
    196 				<input id="ocdi__content-file-upload" type="file" name="content-file-upload">
    197 			</div>
    198 
    199 			<div class="ocdi__file-upload">
    200 				<h3><label for="widget-file-upload"><?php esc_html_e( 'Choose a WIE or JSON file for widget import:', 'pt-ocdi' ); ?></label></h3>
    201 				<input id="ocdi__widget-file-upload" type="file" name="widget-file-upload">
    202 			</div>
    203 
    204 			<div class="ocdi__file-upload">
    205 				<h3><label for="customizer-file-upload"><?php esc_html_e( 'Choose a DAT file for customizer import:', 'pt-ocdi' ); ?></label></h3>
    206 				<input id="ocdi__customizer-file-upload" type="file" name="customizer-file-upload">
    207 			</div>
    208 
    209 			<?php if ( class_exists( 'ReduxFramework' ) ) : ?>
    210 				<div class="ocdi__file-upload">
    211 					<h3><label for="redux-file-upload"><?php esc_html_e( 'Choose a JSON file for Redux import:', 'pt-ocdi' ); ?></label></h3>
    212 					<input id="ocdi__redux-file-upload" type="file" name="redux-file-upload">
    213 					<div>
    214 						<label for="redux-option-name" class="ocdi__redux-option-name-label"><?php esc_html_e( 'Enter the Redux option name:', 'pt-ocdi' ); ?></label>
    215 						<input id="ocdi__redux-option-name" type="text" name="redux-option-name">
    216 					</div>
    217 				</div>
    218 			<?php endif; ?>
    219 		</div>
    220 
    221 		<p class="ocdi__button-container">
    222 			<button class="ocdi__button  button  button-hero  button-primary  js-ocdi-import-data"><?php esc_html_e( 'Import Demo Data', 'pt-ocdi' ); ?></button>
    223 		</p>
    224 
    225 		<?php
    226 	elseif ( 1 === count( $predefined_themes ) ) :
    227 
    228 		?>
    229 		<div class="ocdi__demo-import-notice  js-ocdi-demo-import-notice">
    230 			<?php
    231 			// include get_template_directory() . '/framework/dashboard/admin/system-status.php';
    232 
    233 			// $system_status = new \SDS_REST_System_Status_Controller();
    234 			$environment = get_demo_environment_info();
    235 
    236 			$req_arr = array();
    237 
    238 			?>
    239 			<ul>
    240 
    241 				<?php
    242 				if ( version_compare( $environment['php_version'], '7.2', '>=' ) ) {
    243 					$req_arr['php_version'] = 1;
    244 					echo '<li class="success">' . esc_html__( 'PHP Version: OK.', 'pt-ocdi' ) . '</li>';
    245 				} else {
    246 					$req_arr['php_version'] = 0;
    247 					echo '<li class="error">' . esc_html__( 'PHP Version: Not Ok', 'pt-ocdi' ) . '</li>';
    248 				}
    249 				?>
    250 				<?php
    251 				$max_size = $environment['wp_memory_limit'] / 1048576;
    252 				if ( $max_size >= 128 ) {
    253 					$req_arr['wp_memory_limit'] = 1;
    254 				} else {
    255 					$req_arr['wp_memory_limit'] = 0;
    256 					echo '<li class="error">' . esc_html__( 'PHP memory limit: You need to increase your WordPress memory limit', 'pt-ocdi' ) . '</li>';
    257 				}
    258 				?>
    259 				<?php
    260 				$max_size = $environment['php_post_max_size'] / 1048576;
    261 				if ( $max_size >= 64 ) {
    262 					$req_arr['php_post_max_size'] = 1;
    263 				} else {
    264 					$req_arr['php_post_max_size'] = 0;
    265 					echo '<li class="error">' . esc_html__( 'PHP post max size: You need to increase your post max size', 'pt-ocdi' ) . '</li>';
    266 				}
    267 				?>
    268 				<?php
    269 				if ( $environment['php_max_execution_time'] >= 300 ) {
    270 					$req_arr['php_max_execution_time'] = 1;
    271 				} else {
    272 					$req_arr['php_max_execution_time'] = 0;
    273 					echo '<li class="error">' . esc_html__( 'PHP max execution time: You need to increase your PHP Max execution time', 'pt-ocdi' ) . '</li>';
    274 				}
    275 				?>
    276 				<?php
    277 				if ( $environment['php_max_input_vars'] >= 1000 ) {
    278 					$req_arr['php_max_input_vars'] = 1;
    279 				} else {
    280 					$req_arr['php_max_input_vars'] = 0;
    281 					echo '<li class="error">' . esc_html__( 'PHP max input vars:: You need to increase your PHP Max Input Vars', 'pt-ocdi' ) . '</li>';
    282 				}
    283 				?>
    284 				<?php
    285 				$max_size = $environment['max_upload_size'] / 1048576;
    286 				if ( $max_size >= 32 ) {
    287 					$req_arr['max_upload_size'] = 1;
    288 				} else {
    289 					$req_arr['max_upload_size'] = 0;
    290 					echo '<li class="error">' . esc_html__( 'PHP max upload size:: You need to increase your PHP Max Upload Size', 'pt-ocdi' ) . '</li>';
    291 				}
    292 				?>
    293 				<?php
    294 				$flag = 0;
    295 				if ( isset( $req_arr ) ) {
    296 					if ( is_array( $req_arr ) && ! empty( $req_arr ) ) {
    297 						foreach ( $req_arr as $req ) {
    298 							if ( $req == 1 ) {
    299 								$flag = 1;
    300 							} else {
    301 								$flag = 0;
    302 								break;
    303 							}
    304 						}
    305 					}
    306 				}
    307 				?>
    308 				<?php
    309 				if ( $flag ) {
    310 					echo '<li class="success"><p>' . esc_html__( 'You are all set to import your demo', 'pt-ocdi' ) . '</p></li>';
    311 				} else {
    312 					?>
    313 					<li>
    314 						<a class="syst-link" href="<?php menu_page_url( 'envato-theme-license-system-status' ); ?>">
    315 							<?php
    316 							echo esc_html__( 'Go to System Status Page to See Your Server System Status', 'pt-ocdi' );
    317 							?>
    318 						</a>
    319 					</li>
    320 					<?php
    321 				}
    322 				?>
    323 
    324 
    325 			</ul>
    326 		</div>
    327 
    328 		<?php
    329 		if ( $flag ) {
    330 			?>
    331 			<p class="ocdi__button-container">
    332 				<button class="ocdi__button  button  button-hero  button-primary  js-ocdi-import-data"><?php esc_html_e( 'Import Demo Data', 'pt-ocdi' ); ?></button>
    333 			</p>
    334 			<?php
    335 		}
    336 		?>
    337 
    338 	<?php else : ?>
    339 
    340 		<!-- OCDI grid layout -->
    341 		<div class="ocdi__gl  js-ocdi-gl">
    342 			<?php
    343 			// Prepare navigation data.
    344 			$categories = Helpers::get_all_demo_import_categories( $predefined_themes );
    345 			?>
    346 			<?php if ( ! empty( $categories ) ) : ?>
    347 				<div class="ocdi__gl-header  js-ocdi-gl-header">
    348 					<nav class="ocdi__gl-navigation">
    349 						<ul>
    350 							<li class="active"><a href="#all" class="ocdi__gl-navigation-link  js-ocdi-nav-link"><?php esc_html_e( 'All', 'pt-ocdi' ); ?></a></li>
    351 							<?php foreach ( $categories as $key => $name ) : ?>
    352 								<li><a href="#<?php echo esc_attr( $key ); ?>" class="ocdi__gl-navigation-link  js-ocdi-nav-link"><?php echo esc_html( $name ); ?></a></li>
    353 							<?php endforeach; ?>
    354 						</ul>
    355 					</nav>
    356 					<div clas="ocdi__gl-search">
    357 						<input type="search" class="ocdi__gl-search-input  js-ocdi-gl-search" name="ocdi-gl-search" value="" placeholder="<?php esc_html_e( 'Search demos...', 'pt-ocdi' ); ?>">
    358 					</div>
    359 				</div>
    360 			<?php endif; ?>
    361 			<div class="ocdi__gl-item-container  wp-clearfix  js-ocdi-gl-item-container">
    362 				<?php foreach ( $predefined_themes as $index => $import_file ) : ?>
    363 					<?php
    364 					// Prepare import item display data.
    365 					$img_src = isset( $import_file['import_preview_image_url'] ) ? $import_file['import_preview_image_url'] : '';
    366 					// Default to the theme screenshot, if a custom preview image is not defined.
    367 					if ( empty( $img_src ) ) {
    368 						$theme   = wp_get_theme();
    369 						$img_src = $theme->get_screenshot();
    370 					}
    371 
    372 					?>
    373 					<div class="ocdi__gl-item js-ocdi-gl-item" data-categories="<?php echo esc_attr( Helpers::get_demo_import_item_categories( $import_file ) ); ?>" data-name="<?php echo esc_attr( strtolower( $import_file['import_file_name'] ) ); ?>">
    374 						<div class="ocdi__gl-item-image-container">
    375 							<?php if ( ! empty( $img_src ) ) : ?>
    376 								<img class="ocdi__gl-item-image" src="<?php echo esc_url( $img_src ); ?>">
    377 							<?php else : ?>
    378 								<div class="ocdi__gl-item-image  ocdi__gl-item-image--no-image">
    379 									<?php esc_html_e( 'No preview image . ', 'pt - ocdi' ); ?></div>
    380 							<?php endif; ?>
    381 						</div>
    382 						<div class="ocdi__gl-item-footer<?php echo ! empty( $import_file['preview_url'] ) ? '  ocdi__gl - item - footer--with - preview' : ''; ?>">
    383 							<h4 class="ocdi__gl-item-title" title="<?php echo esc_attr( $import_file['import_file_name'] ); ?>">
    384 								<?php echo esc_html( $import_file['import_file_name'] ); ?></h4>
    385 							<button class="ocdi__gl-item-button  button  button-primary  js-ocdi-gl-import-data" value="<?php echo esc_attr( $index ); ?>"><?php esc_html_e( 'Import', 'pt - ocdi' ); ?></button>
    386 							<?php if ( ! empty( $import_file['preview_url'] ) ) : ?>
    387 								<a class="ocdi__gl-item-button  button" href="<?php echo esc_url( $import_file['preview_url'] ); ?>" target="_blank"><?php esc_html_e( 'Preview', 'pt - ocdi' ); ?></a>
    388 							<?php endif; ?>
    389 						</div>
    390 					</div>
    391 				<?php endforeach; ?>
    392 			</div>
    393 		</div>
    394 
    395 		<div id="js-ocdi-modal-content"></div>
    396 
    397 	<?php endif; ?>
    398 
    399 	<p class="ocdi__ajax-loader  js-ocdi-ajax-loader">
    400 		<span class="spinner"></span> <?php esc_html_e( 'Importing, please wait!', 'pt-ocdi' ); ?>
    401 	</p>
    402 
    403 	<div class="ocdi__response  js-ocdi-ajax-response"></div>
    404 </div>