PluginProbe
Stream – Activity Log & Audit Trail / 4.0.2
Stream – Activity Log & Audit Trail v4.0.2
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-export.php +33 -24 3.0.54.0.2 View file →
@@ -1,10 +1,19 @@
1 1 <?php
2 +/**
3 + * Loads & Manages exporter classes.
4 + *
5 + * @package WP_Stream
6 + */
7 +
2 8 namespace WP_Stream;
3 9
10 +/**
11 + * Class - Export
12 + */
4 13 class Export {
5 14 /**
6 - * Hold Plugin class
15 + * Holds instance of plugin object
7 16 *
8 17 * @var Plugin
9 18 */
10 19 public $plugin;
@@ -19,9 +28,8 @@
19 28 /**
20 29 * Class constructor
21 30 *
22 31 * @param Plugin $plugin The plugin object.
23 - * @return void
24 32 */
25 33 public function __construct( $plugin ) {
26 34 $this->plugin = $plugin;
27 35
@@ -37,8 +45,13 @@
37 45 *
38 46 * @return void
39 47 */
40 48 public function render_download() {
49 + $nonce = wp_stream_filter_input( INPUT_GET, 'stream_record_actions_nonce' );
50 + if ( ! wp_verify_nonce( $nonce, 'stream_record_actions_nonce' ) ) {
51 + return;
52 + }
53 +
41 54 $action = wp_stream_filter_input( INPUT_GET, 'record-actions' );
42 55 if ( strpos( $action, 'export-' ) !== 0 ) {
43 56 return;
44 57 }
@@ -55,27 +68,29 @@
55 68 add_filter( 'wp_stream_list_table_columns', array( $this, 'expand_columns' ), 10, 1 );
56 69
57 70 $records = $list_table->get_records();
58 71 $columns = $list_table->get_columns();
59 - $output = array();
72 + $output = array();
60 73 foreach ( $records as $item ) {
61 74 $output[] = $this->build_record( $item, $columns );
62 75 }
63 76
64 77 $exporters = $this->get_exporters();
65 - $exporter = $exporters[ $output_type ];
78 + $exporter = $exporters[ $output_type ];
66 79 $exporter->output_file( $output, $columns );
67 - return;
68 80 }
69 81
70 82 /**
71 83 * Add Export options to record actions menu
72 84 *
85 + * @param array $action_menu_items Export types.
86 + *
73 87 * @return array
74 88 */
75 - function actions_menu_export_items( $action_menu_items ) {
89 + public function actions_menu_export_items( $action_menu_items ) {
76 90 foreach ( $this->get_exporters() as $exporter ) {
77 91 $action = 'export-' . $exporter->slug;
92 + /* translators: %s: an export format (e.g. "CSV") */
78 93 $action_menu_items[ $action ] = sprintf( __( 'Export as %s', 'stream' ), $exporter->name );
79 94 }
80 95
81 96 return $action_menu_items;
@@ -87,25 +102,25 @@
87 102 * @param array $item Post to extract data from.
88 103 * @param array $columns Columns being extracted.
89 104 * @return array Numerically-indexed array with extracted data.
90 105 */
91 - function build_record( $item, $columns ) {
106 + public function build_record( $item, $columns ) {
92 107 $record = new Record( $item );
93 108
94 109 $row_out = array();
95 110 foreach ( array_keys( $columns ) as $column_name ) {
96 111 switch ( $column_name ) {
97 - case 'date' :
98 - $created = date( 'Y-m-d H:i:s', strtotime( $record->created ) );
112 + case 'date':
113 + $created = gmdate( 'Y-m-d H:i:s', strtotime( $record->created ) );
99 114 $row_out[ $column_name ] = get_date_from_gmt( $created, 'Y/m/d h:i:s A' );
100 115 break;
101 116
102 - case 'summary' :
117 + case 'summary':
103 118 $row_out[ $column_name ] = $record->summary;
104 119 break;
105 120
106 - case 'user_id' :
107 - $user = new Author( (int) $record->user_id, (array) maybe_unserialize( $record->user_meta ) );
121 + case 'user_id':
122 + $user = new Author( (int) $record->user_id, (array) $record->user_meta );
108 123 $row_out[ $column_name ] = $user->get_display_name();
109 124 break;
110 125
111 126 case 'connector':
@@ -123,9 +138,9 @@
123 138 case 'blog_id':
124 139 $row_out[ $column_name ] = $record->blog_id;
125 140 break;
126 141
127 - case 'ip' :
142 + case 'ip':
128 143 $row_out[ $column_name ] = $record->{$column_name};
129 144 break;
130 145 }
131 146 }
@@ -135,11 +150,11 @@
135 150
136 151 /**
137 152 * Increase pagination limit for CSV Output
138 153 *
139 - * @param int $records_per_page Old limit for records_per_page.
154 + * @return int
140 155 */
141 - public function disable_paginate( $records_per_page ) {
156 + public function disable_paginate() {
142 157 return 10000;
143 158 }
144 159
145 160 /**
@@ -158,9 +173,9 @@
158 173 'action' => $columns['action'],
159 174 'ip' => $columns['ip'],
160 175 );
161 176
162 - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
177 + if ( is_multisite() && $this->plugin->is_network_activated() ) {
163 178 $new_columns['blog_id'] = __( 'Blog ID', 'stream' );
164 179 }
165 180
166 181 return $new_columns;
@@ -178,9 +193,9 @@
178 193 );
179 194
180 195 $classes = array();
181 196 foreach ( $exporters as $exporter ) {
182 - include_once $this->plugin->locations['dir'] . '/exporters/class-exporter-' . $exporter .'.php';
197 + include_once $this->plugin->locations['dir'] . '/exporters/class-exporter-' . $exporter . '.php';
183 198 $class_name = sprintf( '\WP_Stream\Exporter_%s', str_replace( '-', '_', $exporter ) );
184 199 if ( ! class_exists( $class_name ) ) {
185 200 continue;
186 201 }
@@ -197,18 +212,12 @@
197 212 * @param array $classes An array of Exporter objects. In the format exporter_slug => Exporter_Class()
198 213 */
199 214 $this->exporters = apply_filters( 'wp_stream_exporters', $classes );
200 215
201 - // Ensure that all exporters extend Exporter
216 + // Ensure that all exporters extend Exporter.
202 217 foreach ( $this->exporters as $key => $exporter ) {
203 218 if ( ! $this->is_valid_exporter( $exporter ) ) {
204 219 unset( $this->exporters[ $key ] );
205 - trigger_error(
206 - sprintf(
207 - esc_html__( 'Registered exporter %s does not extend WP_Stream\Exporter.', 'stream' ),
208 - esc_html( get_class( $exporter ) )
209 - )
210 - );
211 220 }
212 221 }
213 222 }
214 223