sh = $sh; // Add tab to settings page $sh->registerSettingsTab(array( "slug" => "export", "name" => _x("Export", "Export dropin: Tab name on settings page", "simple-history"), "function" => array($this, "output") )); add_action("init", array($this, "downloadExport")); } public function downloadExport() { global $wpdb; $table_name = $wpdb->prefix . SimpleHistory::DBTABLE; $table_name_contexts = $wpdb->prefix . SimpleHistory::DBTABLE_CONTEXTS; if ( isset($_POST["simple-history-action"]) && $_POST["simple-history-action"] === "export-history" ) { // Will die if nonce not valid check_admin_referer( __CLASS__ . "-action-export" ); $export_format = isset( $_POST["format"] ) ? $_POST["format"] : "json"; // Disable relative time output in header add_filter("simple_history/header_time_ago_max_time", "__return_zero"); add_filter("simple_history/header_just_now_max_time", "__return_zero"); // Don't use "You" if event is initiated by the same user that does the export add_filter("simple_history/header_initiator_use_you", "__return_false"); $query = new SimpleHistoryLogQuery(); $query_args = array( "paged" => 1, "posts_per_page" => 3000 ); $events = $query->query($query_args); // $events->total_row_count; $pages_count = $events["pages_count"]; $page_current = $events["page_current"]; $fp = fopen('php://output', 'w'); #header("Content-Type: application/octet-stream"); if ( "csv" == $export_format ) { $filename = "simple-history-export-" . time() . ".csv"; header("Content-Type: text/plain"); header("Content-Disposition: attachment; filename='{$filename}'"); } else if ( "json" == $export_format ) { $filename = "simple-history-export-" . time() . ".json"; header("Content-Type: application/json"); header("Content-Disposition: attachment; filename='{$filename}'"); } else if ( "html" == $export_format ) { $filename = "simple-history-export-" . time() . ".html"; header("Content-Type: text/html"); #header("Content-Disposition: attachment; filename='{$filename}'"); } // Some formats need to output some stuff before the actual loops if ( "json" == $export_format ) { $json_row = "["; fwrite($fp, $json_row); } else if ( "html" == $export_format ) { $html = sprintf( ' Simple History export '); fwrite($fp, $html); } fclose($fp); flush(); exit; #echo "
done"; } } public function output() { ?>