' ;
// echo $_POST['wptbExportCSV'].'
' ;
// siteurl broken in 3.4.1
$url=get_option('siteurl');
$url=get_option('siteurl')."/wp-admin/?page=wp-topbar.php&action=export&noheader=true";
if ( is_ssl() AND (substr($url, 0, 5) != "https" ) AND ( substr($url, 0, 4) == "http" ) ) {
$url="https".substr($url,4);
}
// $url.="/wp-admin/?page=wp-topbar.php&action=export&noheader=true";
?>
Export Options
Select the Export Options buttons to create either a CSV, SQL (insert) or JSON file for download. Future versions will include an inport functions.
Note: Any PHP text you have entered may cause the CSV export to break a single TopBar into multiple rows in the CSV file.
prefix . "wp_topbar_data";
// select one row from the database to setup for the get_col_info function to display column names in one row
$sql ="SELECT * FROM ".$wptb_table_name." LIMIT 1";
$mycols = $wpdb->query( $sql, ARRAY_A );
$mycols = $wpdb->get_col_info();
$export_output = "";
foreach ($mycols as $column_name => $column_value) {
$export_output .= $column_value.";";
}
// trim the trailing end semicolon from the export
$export_output = substr($export_output, 0, -1);
$export_output .= "\n";
$sql ="SELECT * FROM ".$wptb_table_name." ORDER BY `bar_id`";
$myrows = $wpdb->get_results( $sql, ARRAY_A );
$num_rows=$wpdb->num_rows;
$j=0;
while ( $j < $num_rows ) {
$num_cols = sizeof($myrows[$j]);
$col_count = 0;
foreach ($myrows[$j] as $column_name => $column_value) {
$col_count++;
switch ( $column_name ) :
//format numeric columns
case 'bar_id':
case 'weighting_points':
case 'delay_time':
case 'slide_time':
case 'display_time':
case 'bottom_border_height':
case 'font_size':
case 'padding_top':
case 'padding_bottom':
case 'margin_top':
case 'margin_bottom':
$export_output .= $column_value;
break;
//format the remaining -- as text
default:
$export_output .= "'".($column_value)."'";
endswitch;
if ($col_count < $num_cols)
$export_output .= ';';
else
$export_output .= "\n";
}
$j++;
}
$file = 'wp_topbar_export';
$filename = $file."_".date("Y-m-d_H-i",time());
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename='.$filename.'.csv');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen( $export_output ) );
echo $export_output;
return;
} // End of wptb_export_options_csv
function wptb_export_options_json() {
// no html output is allows in this function
if ( ! isset($_REQUEST['page']) || $_REQUEST['page'] != 'wp-topbar.php' )
return;
global $wpdb;
$wptb_table_name = $wpdb->prefix . "wp_topbar_data";
$sql ="SELECT * FROM ".$wptb_table_name." ORDER BY `bar_id`";
$myrows = $wpdb->get_results( $sql, ARRAY_A );
$num_rows=$wpdb->num_rows;
$settings = array();
$j=0;
while ( $j < $num_rows ) {
foreach ($myrows[$j] as $column_name => $column_value) {
$settings[$j][$column_name] = $column_value ;
}
$j++;
}
// if ( ! $settings ) return;
$json_output = json_encode( (array) $settings );
$file = 'wp_topbar_export';
$filename = $file."_".date("Y-m-d_H-i",time());
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename='.$filename.'.json');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen( $json_output ) );
echo $json_output;
return;
} // End of wptb_export_options_json
function wptb_export_options_sql() {
// no html output is allows in this function
if ( ! isset($_REQUEST['page']) || $_REQUEST['page'] != 'wp-topbar.php' )
return;
global $wpdb;
$wptb_table_name = $wpdb->prefix . "wp_topbar_data";
// select one row from the database to setup for the get_col_info function to display column names in one row
$sql ="SELECT * FROM ".$wptb_table_name." LIMIT 1";
$mycols = $wpdb->query( $sql, ARRAY_A );
$mycols = $wpdb->get_col_info();
$export_output = "";
$insert_columns = "(";
foreach ($mycols as $column_name => $column_value) {
$insert_columns .= $column_value.", ";
}
// trim the trailing end semicolon from the export
$insert_columns = substr($insert_columns, 0, -2).")";
$sql ="SELECT * FROM ".$wptb_table_name." ORDER BY `bar_id`";
$myrows = $wpdb->get_results( $sql, ARRAY_A );
$num_rows=$wpdb->num_rows;
$j=0;
while ( $j < $num_rows ) {
$num_cols = sizeof($myrows[$j]);
$col_count = 0;
foreach ($myrows[$j] as $column_name => $column_value) {
$col_count++;
switch ( $column_name ) :
case 'bar_id': $export_output .= 'INSERT INTO `'.$wptb_table_name.'`
'.$insert_columns.'
VALUES( '.$column_value;
break;
case 'weighting_points':
case 'delay_time':
case 'slide_time':
case 'display_time':
case 'bottom_border_height':
case 'font_size':
case 'padding_top':
case 'padding_bottom':
case 'margin_top':
case 'margin_bottom':
$export_output .= $column_value;
break;
default:
$export_output .= "'".$column_value."'";
break;
endswitch;
if ($col_count < $num_cols)
$export_output .= ', ';
else
$export_output .= ");
";
}
$j++;
}
// if ( ! $settings ) return;
$file = 'wp_topbar_export';
$filename = $file."_".date("Y-m-d_H-i",time());
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename='.$filename.'.sql');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen( $export_output ) );
echo $export_output;
return;
} // End of wptb_export_options_sql
?>