*/
if ( ! function_exists( 'add_action' ) ) {
echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
exit;
}
class Add_Quicktag_Im_Export extends Add_Quicktag_Settings {
static private $classobj = NULL;
// post types for the settings
static private $post_types_for_js;
/**
* Handler for the action 'init'. Instantiates this class.
*
* @access public
* @since 2.0.0
* @return $classobj
*/
public function get_object() {
if ( NULL === self :: $classobj ) {
self :: $classobj = new self;
}
return self :: $classobj;
}
/**
* Constructor, init on defined hooks of WP and include second class
*
* @access public
* @since 0.0.2
* @uses register_activation_hook, register_uninstall_hook, add_action
* @return void
*/
public function __construct() {
$this->post_types_for_js = parent::get_post_types_for_js();
if ( isset( $_GET['addquicktag_download'] ) && check_admin_referer( parent :: $nonce_string ) )
add_action( 'init', array( $this, 'get_export_file' ) );
if ( isset( $_POST['addquicktag_import'] ) && check_admin_referer( parent :: $nonce_string ) )
add_action( 'init', array( $this, 'import_file' ) );
add_action( 'addquicktag_settings_page', array( $this, 'get_im_export_part' ) );
}
/**
* get markup for ex- and import on settings page
*
* @access public
* @since 2.0.0
* @uses wp_nonce_field
* @return string
*/
public function get_im_export_part() {
?>
';
$xml .= "\n" . '' . "\n";
for ( $i = 0; $i < count( $options['buttons'] ); $i++ ) {
$xml .= "\t" . '' . "\n";
foreach( $options['buttons'][$i] as $name => $value ) {
$value = stripslashes( $value );
if ( empty( $value ) ) {
$xml .= "\t\t" . '<' . $name . '/>' . "\n";
} elseif ( preg_match( '/^[0-9]*$/', $value ) ) {
$xml .= "\t\t" . '<' . $name . '>' . $value . '' . $name . '>' . "\n";
} else {
$xml .= "\t\t" . '<' . $name . '>' . $name . '>' . "\n";
}
}
$xml .= "\t" . '' . "\n";
}
$xml .= '';
} else {
$xml = 'We dont find settings in database';
}
$filename = urlencode( 'addquicktag.' . date('Y-m-d') . '.xml' );
$filesize = strlen( $xml );
$this -> export_xml( $filename, $filesize, $filetype = 'text/xml' );
echo $xml;
exit;
}
/**
* Create download file
*
* @access public
* @since 2.0.0
* @param string $filename
* @param string $filesize
* @param string $filetype
* @uses get_option
* @return void
*/
public function export_xml( $filename, $filesize, $filetype ) {
header( 'Content-Description: File Transfer' );
header( 'Content-Disposition: attachment; filename=' . $filename );
header( 'Content-Length: ' . $filesize );
header( 'Content-type: ' . $filetype . '; charset=' . get_option('blog_charset'), TRUE );
flush();
}
/**
* Import XML and update settings
*
* @access public
* @since 2.0.0
* @param string $filename
* @uses current_user_can, wp_die, is_plugin_active_for_network, update_site_option, update_option
* @return void
*/
public function import_file( $filename = FALSE ) {
if ( ! current_user_can( 'manage_options' ) )
wp_die( __('Options not update - you don‘t have the privilidges to do this!', parent :: get_textdomain() ) );
// use tmp file
if ( ! $filename )
$filename = $_FILES['xml']['tmp_name'];
$filename = preg_replace( "/\<\!\[CDATA\[(.*?)\]\]\>/ies", "'[CDATA]' . base64_encode('$1') . '[/CDATA]'", $filename );
$filename = utf8_encode( $filename );
$matches = simplexml_load_file( $filename );
// create array from xml
$button = array();
foreach ( $matches -> quicktag as $key ) {
foreach ($key as $value) {
$buttons[$value -> getName()] = $value;
}
$button[] = $buttons;
}
$options['buttons'] = $button;
// validate the values from xml
$options = parent :: validate_settings($options);
// update settings in database
if ( is_multisite() && is_plugin_active_for_network( parent :: get_plugin_string() ) )
update_site_option( parent :: get_option_string(), $options );
else
update_option( parent :: get_option_string(), $options );
}
} // end class
$add_quicktag_im_export = Add_Quicktag_Im_Export :: get_object();