| @@ -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; |
| @@ -59,27 +68,29 @@ | ||
| 59 | 68 | add_filter( 'wp_stream_list_table_columns', array( $this, 'expand_columns' ), 10, 1 ); |
| 60 | 69 | |
| 61 | 70 | $records = $list_table->get_records(); |
| 62 | 71 | $columns = $list_table->get_columns(); |
| 63 | - $output = array(); | |
| 72 | + $output = array(); | |
| 64 | 73 | foreach ( $records as $item ) { |
| 65 | 74 | $output[] = $this->build_record( $item, $columns ); |
| 66 | 75 | } |
| 67 | 76 | |
| 68 | 77 | $exporters = $this->get_exporters(); |
| 69 | - $exporter = $exporters[ $output_type ]; | |
| 78 | + $exporter = $exporters[ $output_type ]; | |
| 70 | 79 | $exporter->output_file( $output, $columns ); |
| 71 | - return; | |
| 72 | 80 | } |
| 73 | 81 | |
| 74 | 82 | /** |
| 75 | 83 | * Add Export options to record actions menu |
| 76 | 84 | * |
| 85 | + * @param array $action_menu_items Export types. | |
| 86 | + * | |
| 77 | 87 | * @return array |
| 78 | 88 | */ |
| 79 | - function actions_menu_export_items( $action_menu_items ) { | |
| 89 | + public function actions_menu_export_items( $action_menu_items ) { | |
| 80 | 90 | foreach ( $this->get_exporters() as $exporter ) { |
| 81 | 91 | $action = 'export-' . $exporter->slug; |
| 92 | + /* translators: %s: an export format (e.g. "CSV") */ | |
| 82 | 93 | $action_menu_items[ $action ] = sprintf( __( 'Export as %s', 'stream' ), $exporter->name ); |
| 83 | 94 | } |
| 84 | 95 | |
| 85 | 96 | return $action_menu_items; |
| @@ -91,25 +102,25 @@ | ||
| 91 | 102 | * @param array $item Post to extract data from. |
| 92 | 103 | * @param array $columns Columns being extracted. |
| 93 | 104 | * @return array Numerically-indexed array with extracted data. |
| 94 | 105 | */ |
| 95 | - function build_record( $item, $columns ) { | |
| 106 | + public function build_record( $item, $columns ) { | |
| 96 | 107 | $record = new Record( $item ); |
| 97 | 108 | |
| 98 | 109 | $row_out = array(); |
| 99 | 110 | foreach ( array_keys( $columns ) as $column_name ) { |
| 100 | 111 | switch ( $column_name ) { |
| 101 | - case 'date' : | |
| 102 | - $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 ) ); | |
| 103 | 114 | $row_out[ $column_name ] = get_date_from_gmt( $created, 'Y/m/d h:i:s A' ); |
| 104 | 115 | break; |
| 105 | 116 | |
| 106 | - case 'summary' : | |
| 117 | + case 'summary': | |
| 107 | 118 | $row_out[ $column_name ] = $record->summary; |
| 108 | 119 | break; |
| 109 | 120 | |
| 110 | - case 'user_id' : | |
| 111 | - $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 ); | |
| 112 | 123 | $row_out[ $column_name ] = $user->get_display_name(); |
| 113 | 124 | break; |
| 114 | 125 | |
| 115 | 126 | case 'connector': |
| @@ -127,9 +138,9 @@ | ||
| 127 | 138 | case 'blog_id': |
| 128 | 139 | $row_out[ $column_name ] = $record->blog_id; |
| 129 | 140 | break; |
| 130 | 141 | |
| 131 | - case 'ip' : | |
| 142 | + case 'ip': | |
| 132 | 143 | $row_out[ $column_name ] = $record->{$column_name}; |
| 133 | 144 | break; |
| 134 | 145 | } |
| 135 | 146 | } |
| @@ -140,8 +151,9 @@ | ||
| 140 | 151 | /** |
| 141 | 152 | * Increase pagination limit for CSV Output |
| 142 | 153 | * |
| 143 | 154 | * @param int $records_per_page Old limit for records_per_page. |
| 155 | + * @return int | |
| 144 | 156 | */ |
| 145 | 157 | public function disable_paginate( $records_per_page ) { |
| 146 | 158 | return 10000; |
| 147 | 159 | } |
| @@ -162,9 +174,9 @@ | ||
| 162 | 174 | 'action' => $columns['action'], |
| 163 | 175 | 'ip' => $columns['ip'], |
| 164 | 176 | ); |
| 165 | 177 | |
| 166 | - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 178 | + if ( is_multisite() && $this->plugin->is_network_activated() ) { | |
| 167 | 179 | $new_columns['blog_id'] = __( 'Blog ID', 'stream' ); |
| 168 | 180 | } |
| 169 | 181 | |
| 170 | 182 | return $new_columns; |
| @@ -201,18 +213,12 @@ | ||
| 201 | 213 | * @param array $classes An array of Exporter objects. In the format exporter_slug => Exporter_Class() |
| 202 | 214 | */ |
| 203 | 215 | $this->exporters = apply_filters( 'wp_stream_exporters', $classes ); |
| 204 | 216 | |
| 205 | - // Ensure that all exporters extend Exporter | |
| 217 | + // Ensure that all exporters extend Exporter. | |
| 206 | 218 | foreach ( $this->exporters as $key => $exporter ) { |
| 207 | 219 | if ( ! $this->is_valid_exporter( $exporter ) ) { |
| 208 | 220 | unset( $this->exporters[ $key ] ); |
| 209 | - trigger_error( | |
| 210 | - sprintf( | |
| 211 | - esc_html__( 'Registered exporter %s does not extend WP_Stream\Exporter.', 'stream' ), | |
| 212 | - esc_html( get_class( $exporter ) ) | |
| 213 | - ) | |
| 214 | - ); | |
| 215 | 221 | } |
| 216 | 222 | } |
| 217 | 223 | } |
| 218 | 224 | |