-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
304 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
includes/iworks/orphans/class-iworks-orphans-export.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
/* | ||
Copyright 2024-PLUGIN_TILL_YEAR Marcin Pietrzak ([email protected]) | ||
this program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License, version 2, as | ||
published by the Free Software Foundation. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
defined( 'ABSPATH' ) || exit; // Exit if accessed directly | ||
/** | ||
* Export Orphans Configuration. | ||
* | ||
* The class allows to export plugin configuration to JSON file. | ||
* | ||
* @since 3.3.0 | ||
*/ | ||
class iWorks_Orphans_Export { | ||
private $options; | ||
|
||
/** | ||
* Prepare and send JSON file | ||
* | ||
* @since 3.3.0 | ||
*/ | ||
public function send_json() { | ||
$this->options = get_orphan_options(); | ||
$options = $this->options->get_group(); | ||
if ( ! is_array( $options ) ) { | ||
return; | ||
} | ||
if ( ! isset( $options['options'] ) ) { | ||
return; | ||
} | ||
$add_wordpress_data = 'true' === filter_input( INPUT_POST, 'extra' ); | ||
/** | ||
* data | ||
*/ | ||
$data = array( | ||
'Meta' => array( | ||
'date' => date( 'c' ), | ||
'plugin' => array( | ||
'name' => 'Orphans', | ||
'version' => 'PLUGIN_VERSION', | ||
), | ||
'url' => array( | ||
'GitHub' => 'https://github.com/iworks/sierotki', | ||
'WordPress' => 'https://wordpress.org/plugins/sierotki/', | ||
), | ||
), | ||
'Orphans' => $this->get_settings_plugin(), | ||
'WordPress' => $add_wordpress_data ? $this->get_wordpress_settings() : array(), | ||
); | ||
/** | ||
* filename | ||
*/ | ||
$filename = sanitize_file_name( | ||
sprintf( | ||
'%s-%s.json', | ||
get_option( 'blogname' ), | ||
date( 'c' ) | ||
) | ||
); | ||
/** | ||
* export file | ||
*/ | ||
header( 'Content-Description: File Transfer' ); | ||
header( 'Content-Type: application/json' ); | ||
header( 'Content-Disposition: attachment; filename=' . $filename ); | ||
header( 'Content-Transfer-Encoding: binary' ); | ||
header( 'Expires: 0' ); | ||
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); | ||
header( 'Pragma: public' ); | ||
echo json_encode( $data, JSON_PRETTY_PRINT ); | ||
exit; | ||
} | ||
|
||
/** | ||
* get plugin settings | ||
* | ||
* @since 3.3.0 | ||
*/ | ||
private function get_settings_plugin() { | ||
$data = array(); | ||
foreach ( $options['options'] as $one ) { | ||
if ( ! isset( $one['name'] ) ) { | ||
continue; | ||
} | ||
$option_name = $this->options->get_option_name( $one['name'] ); | ||
$data[] = array( | ||
'name' => $one['name'], | ||
'option_name' => $this->options->get_option_name( $one['name'] ), | ||
'option_value' => $this->options->get_option( $one['name'] ), | ||
); | ||
} | ||
return $data; | ||
} | ||
|
||
/** | ||
* get WordPress settings | ||
* | ||
* @since 3.3.0 | ||
*/ | ||
private function get_wordpress_settings() { | ||
$fields = array( | ||
'siteurl', | ||
'blogname', | ||
'blog_charset', | ||
'active_plugins', | ||
'WPLANG', | ||
); | ||
$data = array(); | ||
foreach ( $fields as $option_name ) { | ||
$data[ $option_name ] = get_option( $option_name ); | ||
} | ||
return $data; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
// Silence is golden. |
Oops, something went wrong.