summaryrefslogtreecommitdiff
path: root/Postman/Postman-Email-Log/PostmanEmailLogController.php
diff options
context:
space:
mode:
authoryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2019-08-28 20:15:29 +0000
committeryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2019-08-28 20:15:29 +0000
commit5f134fb5839bf3e161385727c2a2009b54444878 (patch)
treec504f5ec5158704dbfd96f74d8675ab228f0070a /Postman/Postman-Email-Log/PostmanEmailLogController.php
parent6372e454198ed7a1a792b5bfd286af1178ae7d63 (diff)
downloadPost-SMTP-5f134fb5839bf3e161385727c2a2009b54444878.zip
security + export csv
Diffstat (limited to 'Postman/Postman-Email-Log/PostmanEmailLogController.php')
-rw-r--r--Postman/Postman-Email-Log/PostmanEmailLogController.php57
1 files changed, 52 insertions, 5 deletions
diff --git a/Postman/Postman-Email-Log/PostmanEmailLogController.php b/Postman/Postman-Email-Log/PostmanEmailLogController.php
index 49f226b..c496455 100644
--- a/Postman/Postman-Email-Log/PostmanEmailLogController.php
+++ b/Postman/Postman-Email-Log/PostmanEmailLogController.php
@@ -72,8 +72,48 @@ class PostmanEmailLogController {
PostmanViewController::JQUERY_SCRIPT,
PostmanViewController::POSTMAN_SCRIPT,
), $pluginData ['version'] );
+ $this->handleCsvExport();
}
+ function handleCsvExport() {
+ if ( ! empty( $_POST ) && ! wp_verify_nonce( $_REQUEST['post-smtp-log'], 'post-smtp' ) )
+ die( 'Security check' );
+
+ if ( isset( $_POST['postman_export_csv'] ) && current_user_can( Postman::MANAGE_POSTMAN_CAPABILITY_LOGS ) ) {
+ $args = array(
+ 'post_type' => PostmanEmailLogPostType::POSTMAN_CUSTOM_POST_TYPE_SLUG,
+ 'post_status' => PostmanEmailLogService::POSTMAN_CUSTOM_POST_STATUS_PRIVATE,
+ 'posts_per_page' => -1,
+ );
+ $logs = new WP_Query($args);
+
+ if ( empty( $logs->posts ) ) {
+ return;
+ }
+
+ header('Content-Type: text/csv');
+ header('Content-Disposition: attachment; filename="email-logs.csv"');
+
+ $fp = fopen('php://output', 'wb');
+
+ $headers = array_keys( PostmanLogFields::get_instance()->get_fields() );
+ fputcsv($fp, $headers);
+
+ foreach ( $logs->posts as $log ) {
+ $meta = PostmanLogFields::get_instance()->get($log->ID);
+ $data = [];
+ foreach ( $meta as $header => $line ) {
+ $data[] = $line[0];
+ }
+ fputcsv($fp, $data);
+ }
+
+ fclose($fp);
+ die();
+
+ }
+ }
+
/**
*/
public function resendMail() {
@@ -404,14 +444,21 @@ class PostmanEmailLogController {
}
?>
</select>
- </div>
- <div class="form-control" style="padding: 0 5px 0 5px;">
+ </div>
+
+ <div class="form-control">
+ <button type="submit" id="postman_export_csv" name="postman_export_csv" class="button button-primary"><?php _e( 'Export To CSV', 'post-smtp' ); ?></button>
+ </div>
+
+ <div class="form-control" style="padding: 0 5px 0 5px; margin-right: 50px;">
<button type="submit" name="filter" class="button button-primary"><?php _e( 'Filter/Search', 'post-smtp' ); ?></button>
- </div>
+ </div>
+
<div class="form-control">
<button type="submit" id="postman_trash_all" name="postman_trash_all" class="button button-primary"><?php _e( 'Trash All', 'post-smtp' ); ?></button>
- </div>
- </div>
+ </div>
+
+ </div>
<div class="error">Please notice: when you select a date for example 11/20/2017, behind the scene the query select <b>11/20/2017 00:00:00</b>.<br>So if you searching for an email arrived that day at any hour you need to select 11/20/2017 as the <b>From Date</b> and 11/21/2017 as the <b>To Date</b>.</div>
</form>