PluginProbe
MainWP Key Maker / trunk
MainWP Key Maker vtrunk
trunk 0.1 0.2 1.0 1.1 1.2 1.3
mainwp-key-maker / mainwp-key-maker.php

mainwp-key-maker.php in MainWP Key Maker trunk, at mainwp-key-maker.php

653 lines 22.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: MainWP Key Maker
4 * Plugin URI: https://mainwp.com/
5 * Description: Easily convert a form into a "key" to use with the MainWP Bulk Settings Manager Extension
6 * Author: MainWP
7 * Author URI: https://mainwp.com
8 * Version: 1.3
9 * License: GPLv2 or later
10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 * Text Domain: mainwp-key-maker
12 */
13
14 // Check whether we made a redirection in this session.
15 $mainwp_key_maker_is_redirect = false;
16
17 // Store current user session id.
18 $mainwp_key_maker_session_id = "";
19
20 if ( ! function_exists( "mainwp_key_maker_get_session_id" ) ) {
21
22 /**
23 * Get current user session id.
24 */
25 function mainwp_key_maker_get_session_id() {
26
27 /**
28 * MainWP Key Maker session ID.
29 *
30 * @global string $mainwp_key_maker_session_id
31 */
32 global $mainwp_key_maker_session_id;
33
34 // We use global so this happen only once .
35 if ( empty( $mainwp_key_maker_session_id ) ) {
36 if ( defined( "AUTH_COOKIE" ) && isset( $_COOKIE[ AUTH_COOKIE ] )) {
37 // Different users can share one account - so use session id
38 $cookie_elements = explode( '|', $_COOKIE[ AUTH_COOKIE ] );
39 if ( isset( $cookie_elements[2] ) ) {
40 $mainwp_key_maker_session_id = substr( (string) $cookie_elements[2], 0, 30 );
41 }
42 } else if ( defined( "SECURE_AUTH_COOKIE" ) && isset( $_COOKIE[ SECURE_AUTH_COOKIE ] ) ) {
43 // Different users can share one account - so use session id
44 $cookie_elements = explode( '|', $_COOKIE[ SECURE_AUTH_COOKIE ] );
45 if ( isset( $cookie_elements[2] ) ) {
46 $mainwp_key_maker_session_id = substr( (string) $cookie_elements[2], 0, 30 );
47 }
48 }
49 }
50 }
51 }
52
53 if ( ! function_exists( "mainwp_key_maker_store_request" ) ) {
54
55 /**
56 * Store $_GET and $_POST inside transient for further use.
57 *
58 * @param false $temp_saving Check whether or not the data is to be temporarily saved.
59 */
60 function mainwp_key_maker_store_request( $temp_saving = false ) {
61
62 /**
63 * @global string $mainwp_key_maker_session_id MainWP Key Maker session ID.
64 * @global bool $mainwp_key_maker_is_redirect Whether this is a redirect.
65 */
66 global $mainwp_key_maker_session_id, $mainwp_key_maker_is_redirect;
67
68 mainwp_key_maker_get_session_id();
69
70 // Only for logged.
71 if ( ! empty( $mainwp_key_maker_session_id ) ) {
72
73 // Skip heartbleed WordPress action.
74 if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'heartbeat' && isset( $_REQUEST['screen_id'] ) ) {
75 return;
76 }
77
78 $saved_datas = get_transient( 'mainwp_eir_' . $mainwp_key_maker_session_id );
79
80 if ( $saved_datas === false ) {
81 $saved_datas = array();
82 }
83
84 $previous_datas = array();
85
86 if ( !$temp_saving ) {
87 foreach ( $saved_datas as $data_counter => $data ) {
88 if ( isset( $data['_temp_saving'] ) ) {
89 continue; // avoid.
90 }
91 $previous_datas[] = $data;
92 }
93 } else {
94 $previous_datas = $saved_datas;
95 }
96
97 $datas = array();
98
99 // Store values in transient so we have access to them in next page.
100 $datas['post'] = $_POST;
101 $datas['get'] = $_GET;
102 $datas['url'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
103 $datas['time'] = time();
104
105 if ($temp_saving) {
106 $datas['_temp_saving'] = true;
107 }
108
109 $previous_datas[] = $datas;
110
111 set_transient( 'mainwp_eir_' . $mainwp_key_maker_session_id, $previous_datas, 90 );
112 $mainwp_key_maker_is_redirect = true;
113 }
114 }
115 }
116
117 // We add additional functionality to wp_redirect and wp_verify_nonce for administrators.
118 if ( ! function_exists( 'wp_redirect' ) ) :
119
120 /**
121 * Redirects to another page
122 * Additionally, stores $_GET, $_POST and url in transient.
123 *
124 * @since 1.5.1
125 *
126 * @global bool $is_IIS
127 *
128 * @param string $location The path to redirect to.
129 * @param int $status Status code to use.
130 *
131 * @return bool False if $location is not provided, true otherwise.
132 */
133 function wp_redirect( $location, $status = 302 ) {
134
135 /** @global object $is_IIS IIS instance. */
136 global $is_IIS;
137
138 /**
139 * Filter the redirect location.
140 *
141 * @since 2.1.0
142 *
143 * @param string $location The path to redirect to.
144 * @param int $status Status code to use.
145 */
146 $location = apply_filters( 'wp_redirect', $location, $status );
147
148 /**
149 * Filter the redirect status code.
150 *
151 * @since 2.3.0
152 *
153 * @param int $status Status code to use.
154 * @param string $location The path to redirect to.
155 */
156 $status = apply_filters( 'wp_redirect_status', $status, $location );
157
158 if ( ! $location ) {
159 return false;
160 }
161
162 $location = wp_sanitize_redirect( $location );
163
164 if ( ! $is_IIS && PHP_SAPI != 'cgi-fcgi' ) {
165 status_header( $status );
166 } // This causes problems on IIS and some FastCGI setups.
167
168 mainwp_key_maker_store_request();
169
170 header( "Location: $location", true, $status );
171
172 return true;
173 }
174 endif;
175
176 if ( ! function_exists( 'wp_verify_nonce' ) ) :
177
178 /**
179 * Verify that correct nonce was used with time limit,
180 * Additionally stores name of nonce action in transient.
181 *
182 * The user is given an amount of time to use the token, so therefore, since the
183 * UID and $action remain the same, the independent variable is the time.
184 *
185 * @since 2.0.3
186 *
187 * @param string $nonce Nonce that was used in the form to verify.
188 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
189 *
190 * @return false|int False if the nonce is invalid, 1 if the nonce is valid and generated between
191 * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.
192 */
193 function wp_verify_nonce( $nonce, $action = - 1 ) {
194
195 /**
196 * MainWP Key Maker session ID.
197 *
198 * @global string $mainwp_key_maker_session_id
199 */
200 global $mainwp_key_maker_session_id;
201
202 if ( ! empty( $mainwp_key_maker_session_id ) ) {
203 $key_maker = get_transient( 'mainwp_ein_' . $mainwp_key_maker_session_id );
204 if ( $key_maker === false ) {
205 $key_maker = array();
206 }
207
208 $key_maker[ trim( $nonce ) ] = $action;
209 set_transient( 'mainwp_ein_' . $mainwp_key_maker_session_id, $key_maker );
210 }
211
212 $nonce = (string) $nonce;
213 $user = wp_get_current_user();
214 $uid = (int) $user->ID;
215 if ( ! $uid ) {
216
217 /**
218 * Filter whether the user who generated the nonce is logged out.
219 *
220 * @since 3.5.0
221 *
222 * @param int $uid ID of the nonce-owning user.
223 * @param string $action The nonce action.
224 */
225 $uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
226 }
227
228 if ( empty( $nonce ) ) {
229 return false;
230 }
231
232 $token = wp_get_session_token();
233 $i = wp_nonce_tick();
234
235 // Nonce generated 0-12 hours ago.
236 $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), - 12, 10 );
237 if ( hash_equals( $expected, $nonce ) ) {
238 return 1;
239 }
240
241 // Nonce generated 12-24 hours ago.
242 $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), - 12, 10 );
243 if ( hash_equals( $expected, $nonce ) ) {
244 return 2;
245 }
246
247 // Invalid nonce.
248 return false;
249 }
250 endif;
251
252 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
253
254 // We want to support ajax calls also.
255 mainwp_key_maker_store_request();
256 }
257
258 /**
259 * Class MainWP_Key_Maker.
260 */
261 class MainWP_Key_Maker {
262
263 /**
264 * MainWP_Key_Maker constructor.
265 */
266 public function __construct() {
267 add_action( 'init', array( $this, 'init' ) );
268 }
269
270 /**
271 * Initiate
272 */
273 public function init() {
274 mainwp_key_maker_get_session_id();
275
276 if ( ! current_user_can( 'manage_options' ) || ! is_admin() ) {
277 return;
278 }
279
280 /** @global bool $mainwp_key_maker_is_redirect Redirect check. */
281 global $mainwp_key_maker_is_redirect;
282
283 // Display redirect data on next page.
284 if ( $mainwp_key_maker_is_redirect ) {
285 return;
286 }
287
288 // Skip Ajax.
289 if ( defined( 'XMLRPC_REQUEST' ) || defined( 'DOING_AJAX' ) || defined( 'IFRAME_REQUEST' ) ) {
290 return;
291 }
292
293 // Don't process if fatal error.
294 $error = error_get_last();
295 if ( ! empty( $error ) && ( $error['type'] & ( E_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR ) ) ) {
296 return;
297 }
298
299 // temporary saving to fix if none wp-redirect.
300 mainwp_key_maker_store_request($temp = true);
301
302 add_action( 'wp_before_admin_bar_render', array( $this, 'bar_render' ), 999 );
303 add_action( 'admin_footer', array( $this, 'toolbar' ), 999 );
304 }
305
306 /**
307 * Render Key Maker button inside admin bar &
308 * Display content using thickbox popup.
309 */
310 public function bar_render() {
311
312 /** @global object $wp_admin_bar WordPress Admin Bar instance. */
313 global $wp_admin_bar;
314
315 wp_register_script( 'mainwp-key-maker-colorbox', plugins_url( '/js/jquery.colorbox-min.js', __FILE__ ), array( 'jquery' ) );
316 wp_enqueue_script( 'mainwp-key-maker-colorbox' );
317
318 wp_enqueue_script( 'mainwp-clipboard', plugins_url( '/js/clipboard.min.js', __FILE__ ), array( 'jquery' ) );
319
320 wp_register_style( 'mainwp-key-maker-colorbox', plugins_url( '/css/colorbox.css', __FILE__ ) );
321 wp_enqueue_style( 'mainwp-key-maker-colorbox' );
322
323 $args = array(
324 'id' => 'mainwp-key-maker-adminbar-node',
325 'title' => __( 'MainWP Key Maker', 'mainwp-key-maker' ),
326 'href' => '#mainwp-key-maker-box'
327 );
328
329 $wp_admin_bar->add_node( $args );
330 ?>
331 <style>
332 #wp-admin-bar-mainwp-key-maker {
333 cursor: pointer;
334 }
335 .mainwp-km-info {
336 margin-top: 1em;
337 padding: .6em;
338 border-left: 4px Solid #7fb100;
339 box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
340 -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
341 }
342 </style>
343 <script>
344 jQuery( document ).ready( function ($) {
345 new ClipboardJS('.mainwp-key-maker-copy-button');
346 //Copy to clipboard.
347 jQuery(document).on('click', '.mainwp-key-maker-copy-button', function () {
348 var btn = this;
349 jQuery(btn).val('<?php echo esc_js( __('Copied to Clipboard!', 'mainwp-key-maker') ); ?>');
350 jQuery(btn).removeClass('button-primary');
351 setInterval(function () {
352 jQuery(btn).val('<?php echo esc_js( __('Copy to Clipboard', 'mainwp-key-maker') ); ?>');
353 jQuery(btn).addClass('button-primary');
354 }, 3000);
355 return false;
356 });
357
358 jQuery("#wp-admin-bar-mainwp-key-maker-adminbar-node a").colorbox({inline: true, width: "1230px"});
359
360 jQuery(".mainwp-key-maker-debug-a").on("click", function () {
361 jQuery("#mainwp-key-maker-debug-" + jQuery(this).attr("ids")).toggle();
362 });
363 });
364 </script>
365
366 <?php
367 }
368
369 /**
370 * Display content for admin bar button.
371 */
372 public function toolbar() {
373 /**
374 * MainWP Key Maker session ID.
375 *
376 * @global string $mainwp_key_maker_session_id
377 */
378 global $mainwp_key_maker_session_id;
379
380 // Check if we have anything to display.
381 $is_any_info = false;
382 $is_there_pre_request = false;
383 ?>
384 <div style="display:none;">
385 <div id="mainwp-key-maker-box">
386 <span style="float: right;">
387 <a href="https://mainwp.com" target="_blank" title="MainWP"><img style="height: 40px; margin-right: 15px;" src="<?php echo esc_url( plugins_url( 'images/logo.png', __FILE__ ) ); ?>" alt="MainWP" /></a>
388 </span>
389 <h1><?php esc_html_e( 'MainWP Key Maker', 'mainwp-key-maker' ); ?></h1>
390 <div style="clear: both;"></div>
391 <?php
392
393 $nonce = get_transient( 'mainwp_ein_' . $mainwp_key_maker_session_id );
394
395 if ( $nonce === false ) {
396 $nonce = array();
397 }
398
399 $previous_datas = get_transient( 'mainwp_eir_' . $mainwp_key_maker_session_id );
400
401 if ( $previous_datas !== false ) {
402 delete_transient( 'mainwp_ein_' . $mainwp_key_maker_session_id );
403 delete_transient( 'mainwp_eir_' . $mainwp_key_maker_session_id );
404 foreach ( $previous_datas as $previous_counter => $previous_data ):
405 if ( ( isset( $previous_data['post'] ) && ! empty( $previous_data['post'] ) ) || ( isset( $previous_data['get'] ) && ! empty( $previous_data['get'] ) ) ):
406
407 if (isset($previous_data['_temp_saving'])) {
408 unset($previous_data['_temp_saving']);
409 }
410
411 $is_any_info = true;
412 $is_there_pre_request = true;
413 ?>
414 <div style="padding-bottom: 1em; margin-bottom: 1px Solid #000;">
415 <?php
416 if ( $is_there_pre_request ):
417 ?>
418 <div class="mainwp-km-info">
419 <em><?php esc_html_e( 'The "Verify Form Fields and Values" button allows you to tell if the Key will contain the information you want.', 'mainwp-key-maker' ); ?></em><br/>
420 <em><?php esc_html_e( 'If it does not, you may need to submit the form in order for the Key Maker to be able to correctly gather the form fields and values.', 'mainwp-key-maker' ); ?></em>
421 </div>
422 <?php
423 endif;
424 ?>
425 <p>
426 <h2 style="margin-bottom: .3em;"><?php esc_html_e( 'Post-submission Request', 'mainwp-key-maker' ); ?></h2>
427 <em>( <?php echo esc_html( date_i18n( "d-m-Y H:i:s", $previous_data['time'] ) ); ?> )</em>
428 <?php echo( isset( $previous_data['url'] ) ? esc_html( $previous_data['url'] ) : esc_html__( 'Unknown URL', 'mainwp-key-maker' ) ); ?>
429 <span style="float: right; margin-right: 1.5em;">
430 <a href="#" class="mainwp-key-maker-debug-a button" style="text-decoration: none;" ids="<?php echo esc_attr( $previous_counter ); ?>">
431 <?php esc_html_e( 'Verify Form Fields and Values', 'mainwp-key-maker' ); ?>
432 </a>
433 <input type="submit" id="mainwp-key-maker-textarea-previous-<?php echo esc_attr( $previous_counter ); ?>-button" data-clipboard-target="#mainwp-key-maker-textarea-previous-<?php echo esc_attr( $previous_counter ); ?>" class="mainwp-key-maker-copy-button button button-primary" value="<?php esc_attr_e( 'Copy to Clipboard', 'mainwp-key-maker' ); ?>">
434 </span>
435 </p>
436 <div id="mainwp-key-maker-debug-<?php echo esc_attr( $previous_counter ); ?>" style="display:none; width: 1170px !important; margin-bottom: 1em;" class="postbox">
437 <div class="inside">
438 <pre><?php echo $this->custom_print_r( $previous_data, $nonce ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output is escaped within custom_print_r() via esc_html() ?></pre>
439 </div>
440 </div>
441
442 <textarea rows="12" cols="90" style="width: 1170px;" class="mainwp-key-maker-textarea" id="mainwp-key-maker-textarea-previous-<?php echo esc_attr( $previous_counter ); ?>" readonly><?php echo esc_textarea( $this->parse_data( $previous_data, $nonce ) ); ?></textarea>
443 </div>
444 <?php
445 endif;
446 endforeach;
447 }
448
449 $current_data = array();
450 $current_data['post'] = $_POST;
451 $current_data['get'] = $_GET;
452 $current_data['url'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
453 $current_data['time'] = time();
454 ?>
455 <div style="padding-bottom: 1em; margin-bottom: 1px Solid #000;">
456 <?php
457 if ( !empty($current_data['post'] ) || !empty( $current_data['get'] ) ):
458 $is_any_info = true;
459 ?>
460 <?php
461 if ( ! $is_there_pre_request ):
462 ?>
463 <div class="mainwp-km-info">
464 <em><?php esc_html_e( 'The "Verify Form Fields and Values" button allows you to tell if the Key will contain the information you want.', 'mainwp-key-maker' ); ?></em><br/>
465 <em><?php esc_html_e( 'If it does not, you may need to submit the form in order for the Key Maker to be able to correctly gather the form fields and values.', 'mainwp-key-maker' ); ?></em>
466 </div>
467 <?php
468 endif;
469 ?>
470 <p>
471 <h2 style="margin-bottom: .3em;"><?php esc_html_e( 'Pre-submission Request', 'mainwp-key-maker' ); ?></h2>
472 <em>( <?php echo esc_html( date_i18n( "d-m-Y H:i:s", $current_data['time'] ) ); ?> )</em>
473 <?php echo esc_html( $current_data['url'] ); ?>
474 <span style="float: right; margin-right: 1.5em;">
475 <a href="#" class="mainwp-key-maker-debug-a button" ids="current" style="text-decoration: none;"><?php esc_html_e( 'Verify Form Fields and Values', 'mainwp-key-maker' ); ?>
476 </a>
477 <input type="submit" id="mainwp-key-maker-textarea-button" data-clipboard-target="#mainwp-key-maker-textarea" class="mainwp-key-maker-copy-button button button-primary" value="<?php esc_attr_e( 'Copy to clipboard', 'mainwp-key-maker' ); ?>">
478 </span>
479 </p>
480
481 <div id="mainwp-key-maker-debug-current" style="display:none; width: 1170px !important; margin-bottom: 1em;" class="postbox">
482 <div class="inside">
483 <pre><?php echo $this->custom_print_r($current_data, $nonce); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output is escaped within custom_print_r() via esc_html() ?></pre>
484 </div>
485 </div>
486
487
488 <textarea rows="12" cols="90" style="width: 1170px;" class="mainwp-key-maker-textarea" id="mainwp-key-maker-textarea" readonly><?php echo esc_textarea( $this->parse_data( $current_data, $nonce ) ); ?></textarea>
489 <?php
490 endif;
491
492 if ( ! $is_any_info ):
493 ?>
494 <div class="mainwp-km-info"><?php esc_html_e( 'No form detected. You may have to submit the form before Key Maker is able to find the form and make the Key.', 'mainwp-key-maker' ); ?></div>
495 <?php
496 endif;
497 ?>
498 </div>
499 </div>
500 </div>
501 <?php
502 }
503
504 /**
505 * Custom sanitized print_r() function.
506 *
507 * Print $_GET and $_POST using print_r with XSS protection.
508 *
509 * @param string $data Data to print.
510 * @param string $nonce Security nonce.
511 *
512 * @return string Return escaped string & print to screen.
513 */
514 public function custom_print_r( $data, $nonce ) {
515 return esc_html( print_r( $this->check_nonces( $data, $nonce ), true ) );
516 }
517
518 /**
519 * Recursive check if nonce field exists in array.
520 *
521 * @param array $data Data to print.
522 * @param string $nonce Security nonce.
523 *
524 * @return array Return trimmed array.
525 */
526 public function check_nonces( $data, $nonce ) {
527 $new = array();
528 foreach ( $data as $key => $val ) {
529 if ( is_array( $val ) ) {
530 $new[ $key ] = $this->check_nonces( $val, $nonce );
531 } else {
532 $val = trim( $val );
533 if ( isset( $nonce[ $val ] ) ) {
534 $new[ $key ] = __( 'NONCE FIELD', 'mainwp-key-maker' ) . ' - ' . $nonce[ $val ];
535 } else {
536 $new[ $key ] = $val;
537 }
538 }
539 }
540
541 return $new;
542 }
543
544 /**
545 * Parse data in readable format for Skeleton Key.
546 *
547 * @param array $data Data to print.
548 * @param string $nonce Security nonce.
549 *
550 * @return string Return string in readable format.
551 */
552 public function parse_data( $data, $nonce ) {
553 $out = array();
554 if ( isset( $data['post'] ) ) {
555 foreach ( $this->flatten_array( $data['post'] ) as $key => $val ) {
556 $array = array();
557 $val = trim( $val );
558
559 if ( isset( $nonce[ $val ] ) ) {
560 $array['field_type'] = 'nonce_field';
561 $array['nonce_field_name'] = $nonce[ $val ];
562 $array['nonce_field_arg'] = $key;
563 } else {
564 if ( strpos( $val, "\n" ) !== false || strpos( $val, "\r" ) !== false ) {
565 $array['field_type'] = 'textarea_field';
566 $array['textarea_field_description'] = $val;
567 $array['textarea_field_name'] = $key;
568 $array['textarea_field_value'] = $val;
569 $array['textarea_field_type'] = 'post';
570 } else {
571 $array['field_type'] = 'text_field';
572 $array['text_field_description'] = $val;
573 $array['text_field_name'] = $key;
574 $array['text_field_value'] = $val;
575 $array['text_field_type'] = 'post';
576 }
577 }
578
579 $out[] = http_build_query( $array );
580 }
581 }
582
583 if ( isset( $data['get'] ) ) {
584 foreach ( $this->flatten_array( $data['get'] ) as $key => $val ) {
585 $array = array();
586 $val = trim( $val );
587
588 if ( isset( $nonce[ $val ] ) ) {
589 $array['field_type'] = 'nonce_field';
590 $array['nonce_field_name'] = $nonce[ $val ];
591 $array['nonce_field_arg'] = $key;
592 } else {
593 $array['field_type'] = 'text_field';
594 $array['text_field_description'] = $val;
595 $array['text_field_name'] = $key;
596 $array['text_field_value'] = $val;
597 $array['text_field_type'] = 'get';
598 }
599
600 $out[] = http_build_query( $array );
601 }
602 }
603
604 $url = "";
605 if ( isset( $data['url'] ) ) {
606 $url = parse_url( $data['url'] );
607 $url = ( isset( $url['path'] ) ? $url['path'] : '' ) . ( isset( $url['query'] ) ? '?' . $url['query'] : '' );
608 }
609
610 $array = array();
611 $array['field_type'] = 'settings_field';
612 $array['settings_field_name'] = __( 'Imported', 'mainwp-key-maker' ) . ' ' . current_time( "d-m-Y H:i:s" );
613 $array['settings_field_url'] = $url;
614
615 $content = http_build_query( $array ) . '&' . implode( '&', $out );
616 $hash = sha1( $content );
617
618 $return = "-----BEGIN BULK SETTINGS MANAGER KEY-----\r\n";
619 $return .= base64_encode( $hash . '|' . $content );
620 $return .= "\r\n-----END BULK SETTINGS MANAGER KEY-----\r\n";
621
622 return $return;
623 }
624
625 /**
626 * Convert multidimensional array into single dimensional array
627 * Something like http[like][array][structure].
628 *
629 * @param array $array Multidimensional array.
630 * @param string $previous Previous value.
631 *
632 * @return array Return formatted array.
633 */
634 public function flatten_array( $array, $previous = "" ) {
635 $out = array();
636 foreach ( $array as $key => $val ) {
637 if ( is_array( $val ) ) {
638 $out = array_merge( $this->flatten_array( $val, ( $previous == "" ? $key : $previous . '[' . $key . ']' ) ), $out );
639 } else {
640 if ( $previous == "" ) {
641 $out[ $key ] = $val;
642 } else {
643 $out[ $previous . '[' . $key . ']' ] = $val;
644 }
645 }
646 }
647
648 return $out;
649 }
650 }
651
652 $mainWP = new MainWP_Key_Maker();
653