| @@ -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 | } |
| @@ -136,8 +151,9 @@ | ||
| 136 | 151 | /** |
| 137 | 152 | * Increase pagination limit for CSV Output |
| 138 | 153 | * |
| 139 | 154 | * @param int $records_per_page Old limit for records_per_page. |
| 155 | + * @return int | |
| 140 | 156 | */ |
| 141 | 157 | public function disable_paginate( $records_per_page ) { |
| 142 | 158 | return 10000; |
| 143 | 159 | } |
| @@ -158,9 +174,9 @@ | ||
| 158 | 174 | 'action' => $columns['action'], |
| 159 | 175 | 'ip' => $columns['ip'], |
| 160 | 176 | ); |
| 161 | 177 | |
| 162 | - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 178 | + if ( is_multisite() && $this->plugin->is_network_activated() ) { | |
| 163 | 179 | $new_columns['blog_id'] = __( 'Blog ID', 'stream' ); |
| 164 | 180 | } |
| 165 | 181 | |
| 166 | 182 | return $new_columns; |
| @@ -178,9 +194,9 @@ | ||
| 178 | 194 | ); |
| 179 | 195 | |
| 180 | 196 | $classes = array(); |
| 181 | 197 | foreach ( $exporters as $exporter ) { |
| 182 | - include_once $this->plugin->locations['dir'] . '/exporters/class-exporter-' . $exporter .'.php'; | |
| 198 | + include_once $this->plugin->locations['dir'] . '/exporters/class-exporter-' . $exporter . '.php'; | |
| 183 | 199 | $class_name = sprintf( '\WP_Stream\Exporter_%s', str_replace( '-', '_', $exporter ) ); |
| 184 | 200 | if ( ! class_exists( $class_name ) ) { |
| 185 | 201 | continue; |
| 186 | 202 | } |
| @@ -197,18 +213,12 @@ | ||
| 197 | 213 | * @param array $classes An array of Exporter objects. In the format exporter_slug => Exporter_Class() |
| 198 | 214 | */ |
| 199 | 215 | $this->exporters = apply_filters( 'wp_stream_exporters', $classes ); |
| 200 | 216 | |
| 201 | - // Ensure that all exporters extend Exporter | |
| 217 | + // Ensure that all exporters extend Exporter. | |
| 202 | 218 | foreach ( $this->exporters as $key => $exporter ) { |
| 203 | 219 | if ( ! $this->is_valid_exporter( $exporter ) ) { |
| 204 | 220 | 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 | 221 | } |
| 212 | 222 | } |
| 213 | 223 | } |
| 214 | 224 | |